mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
Add getCodeContractBytecode
This commit is contained in:
parent
0f77f8b8a0
commit
cf7efffe92
2 changed files with 25 additions and 1 deletions
|
|
@ -20,6 +20,7 @@ var funcs = map[string]stateManagerFunction{
|
|||
"setStorage(address,bytes32,bytes32)": setStorage,
|
||||
"deployContract(address,bytes,bool,address)": deployContract,
|
||||
"getOvmContractNonce(address)": getOvmContractNonce,
|
||||
"getCodeContractBytecode(address)": getCodeContractBytecode,
|
||||
"incrementOvmContractNonce(address)": incrementOvmContractNonce,
|
||||
}
|
||||
var methodIds map[[4]byte]stateManagerFunction
|
||||
|
|
@ -60,6 +61,12 @@ func getStorage(evm *EVM, contract *Contract, input []byte) (ret []byte, err err
|
|||
return val.Bytes(), nil
|
||||
}
|
||||
|
||||
func getCodeContractBytecode(evm *EVM, contract *Contract, input []byte) (ret []byte, err error) {
|
||||
address := common.BytesToAddress(input[4:36])
|
||||
code := evm.StateDB.GetCode(address)
|
||||
return code, nil
|
||||
}
|
||||
|
||||
func getOvmContractNonce(evm *EVM, contract *Contract, input []byte) (ret []byte, err error) {
|
||||
address := common.BytesToAddress(input[4:36])
|
||||
b := make([]byte, 8)
|
||||
|
|
@ -81,6 +88,6 @@ func deployContract(evm *EVM, contract *Contract, input []byte) (ret []byte, err
|
|||
initCodeLength := binary.BigEndian.Uint32(input[160:164])
|
||||
initCode := input[164 : 164+initCodeLength]
|
||||
callerContractRef := &Contract{self: AccountRef(callerAddress)}
|
||||
returnVal, _, _, _ := evm.OvmCreate(callerContractRef, address, initCode, 0, bigZero)
|
||||
returnVal, _, _, err := evm.OvmCreate(callerContractRef, address, initCode, contract.Gas, bigZero)
|
||||
return returnVal, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,6 +98,23 @@ func TestGetAndIncrementNonce(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestGetCodeContractBytecode(t *testing.T) {
|
||||
state := newState()
|
||||
initCode, _ := hex.DecodeString("6080604052348015600f57600080fd5b5060b28061001e6000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c80639b0b0fda14602d575b600080fd5b606060048036036040811015604157600080fd5b8101908080359060200190929190803590602001909291905050506062565b005b8060008084815260200190815260200160002081905550505056fea265627a7a7231582053ac32a8b70d1cf87fb4ebf5a538ea9d9e773351e6c8afbc4bf6a6c273187f4a64736f6c63430005110032")
|
||||
rawStateManagerAbi, _ := ioutil.ReadFile("./StateManagerABI.json")
|
||||
stateManagerAbi, _ := abi.JSON(strings.NewReader(string(rawStateManagerAbi)))
|
||||
address := common.HexToAddress("9999999999999999999999999999999999999999")
|
||||
callerAddress := common.HexToAddress("42")
|
||||
deployContractCalldata, _ := stateManagerAbi.Pack("deployContract", address, initCode, true, callerAddress)
|
||||
call(t, state, vm.StateManagerAddress, deployContractCalldata)
|
||||
getCodeContractBytecodeCalldata, _ := stateManagerAbi.Pack("getCodeContractBytecode", address)
|
||||
getCodeContractBytecodeReturnValue, _ := call(t, state, vm.StateManagerAddress, getCodeContractBytecodeCalldata)
|
||||
expectedCreatedCode := common.FromHex("6080604052348015600f57600080fd5b506004361060285760003560e01c80639b0b0fda14602d575b600080fd5b606060048036036040811015604157600080fd5b8101908080359060200190929190803590602001909291905050506062565b005b8060008084815260200190815260200160002081905550505056fea265627a7a7231582053ac32a8b70d1cf87fb4ebf5a538ea9d9e773351e6c8afbc4bf6a6c273187f4a64736f6c63430005110032")
|
||||
if !bytes.Equal(getCodeContractBytecodeReturnValue, expectedCreatedCode) {
|
||||
t.Errorf("Expected %020x; got %020x", getCodeContractBytecodeReturnValue, expectedCreatedCode)
|
||||
}
|
||||
}
|
||||
|
||||
func makeUint256WithUint64(num uint64) []byte {
|
||||
b := make([]byte, 8)
|
||||
binary.BigEndian.PutUint64(b, num)
|
||||
|
|
|
|||
Loading…
Reference in a new issue