Skip to content

Commit

Permalink
Merge branch 'master' into evm-events-more-test-assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
ramtinms authored Feb 21, 2024
2 parents bd72a51 + 27793f4 commit 48ffcdd
Show file tree
Hide file tree
Showing 15 changed files with 592 additions and 290 deletions.
4 changes: 2 additions & 2 deletions fvm/evm/emulator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
)

var (
FlowEVMTestnetChainID = big.NewInt(666)
FlowEVMMainnetChainID = big.NewInt(777)
FlowEVMTestnetChainID = big.NewInt(646)
FlowEVMMainnetChainID = big.NewInt(747)
BlockLevelGasLimit = uint64(math.MaxUint64)
zero = uint64(0)
)
Expand Down
9 changes: 7 additions & 2 deletions fvm/evm/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ func TestEVMRun(t *testing.T) {
import EVM from %s
access(all)
fun main(tx: [UInt8], coinbaseBytes: [UInt8; 20]) {
fun main(tx: [UInt8], coinbaseBytes: [UInt8; 20]): EVM.Result {
let coinbase = EVM.EVMAddress(bytes: coinbaseBytes)
EVM.run(tx: tx, coinbase: coinbase)
return EVM.run(tx: tx, coinbase: coinbase)
}
`,
sc.EVMContract.Address.HexWithPrefix(),
Expand Down Expand Up @@ -79,6 +79,11 @@ func TestEVMRun(t *testing.T) {
snapshot)
require.NoError(t, err)
require.NoError(t, output.Err)

res, err := stdlib.ResultSummaryFromEVMResultValue(output.Value)
require.NoError(t, err)
require.Equal(t, types.StatusSuccessful, res.Status)
require.Equal(t, types.ErrCodeNoError, res.ErrorCode)
})
})
}
Expand Down
107 changes: 0 additions & 107 deletions fvm/evm/handler/codeFinder.go

This file was deleted.

64 changes: 17 additions & 47 deletions fvm/evm/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/onflow/flow-go/fvm/environment"
fvmErrors "github.com/onflow/flow-go/fvm/errors"
"github.com/onflow/flow-go/fvm/evm/handler/coa"
"github.com/onflow/flow-go/fvm/evm/precompiles"
"github.com/onflow/flow-go/fvm/evm/types"
"github.com/onflow/flow-go/model/flow"
)
Expand All @@ -35,6 +34,10 @@ func (h *ContractHandler) FlowTokenAddress() common.Address {
return h.flowTokenAddress
}

func (h *ContractHandler) EVMContractAddress() common.Address {
return common.Address(h.evmContractAddress)
}

var _ types.ContractHandler = &ContractHandler{}

func NewContractHandler(
Expand All @@ -52,24 +55,10 @@ func NewContractHandler(
addressAllocator: addressAllocator,
backend: backend,
emulator: emulator,
precompiles: getPrecompiles(evmContractAddress, addressAllocator, backend),
precompiles: preparePrecompiles(evmContractAddress, addressAllocator, backend),
}
}

func getPrecompiles(
evmContractAddress flow.Address,
addressAllocator types.AddressAllocator,
backend types.Backend,
) []types.Precompile {
archAddress := addressAllocator.AllocatePrecompileAddress(1)
archContract := precompiles.ArchContract(
archAddress,
backend.GetCurrentBlockHeight,
COAOwnershipProofValidator(evmContractAddress, backend),
)
return []types.Precompile{archContract}
}

// DeployCOA deploys a cadence-owned-account and returns the address
func (h *ContractHandler) DeployCOA(uuid uint64) types.Address {
addr, err := h.deployCOA(uuid)
Expand Down Expand Up @@ -120,34 +109,19 @@ func (h *ContractHandler) LastExecutedBlock() *types.Block {
return block
}

// Run runs an rlpencoded evm transaction and
// RunOrPanic runs an rlpencoded evm transaction and
// collects the gas fees and pay it to the coinbase address provided.
func (h *ContractHandler) Run(rlpEncodedTx []byte, coinbase types.Address) {
func (h *ContractHandler) RunOrPanic(rlpEncodedTx []byte, coinbase types.Address) {
_, err := h.run(rlpEncodedTx, coinbase)
panicOnAnyError(err)
}

// TryRun tries to run an rlpencoded evm transaction and
// Run tries to run an rlpencoded evm transaction and
// collects the gas fees and pay it to the coinbase address provided.
func (h *ContractHandler) TryRun(rlpEncodedTx []byte, coinbase types.Address) *types.ResultSummary {
func (h *ContractHandler) Run(rlpEncodedTx []byte, coinbase types.Address) *types.ResultSummary {
res, err := h.run(rlpEncodedTx, coinbase)
rs := &types.ResultSummary{
Status: types.StatusSuccessful,
}
if err != nil {
panicOnFatalOrBackendError(err)
// remaining errors are validation errors
rs.ErrorCode = ValidationErrorCode(err)
rs.Status = types.StatusInvalid
return rs
}
if res.VMError != nil {
rs.ErrorCode = ExecutionErrorCode(res.VMError)
rs.Status = types.StatusFailed
rs.GasConsumed = res.GasConsumed
}
rs.GasConsumed = res.GasConsumed
return rs
panicOnFatalOrBackendError(err)
return types.NewResultSummary(res, err)
}

func (h *ContractHandler) run(
Expand Down Expand Up @@ -584,13 +558,13 @@ func (a *Account) deploy(code types.Code, gaslimit types.GasLimit, balance types
// it would limit the gas used according to the limit provided
// given it doesn't goes beyond what Flow transaction allows.
// the balance would be deducted from the OFA account and would be transferred to the target address
func (a *Account) Call(to types.Address, data types.Data, gaslimit types.GasLimit, balance types.Balance) types.Data {
data, err := a.call(to, data, gaslimit, balance)
panicOnAnyError(err)
return data
func (a *Account) Call(to types.Address, data types.Data, gaslimit types.GasLimit, balance types.Balance) *types.ResultSummary {
res, err := a.call(to, data, gaslimit, balance)
panicOnFatalOrBackendError(err)
return types.NewResultSummary(res, err)
}

func (a *Account) call(to types.Address, data types.Data, gaslimit types.GasLimit, balance types.Balance) (types.Data, error) {
func (a *Account) call(to types.Address, data types.Data, gaslimit types.GasLimit, balance types.Balance) (*types.Result, error) {
ctx, err := a.precheck(true, gaslimit)
if err != nil {
return nil, err
Expand All @@ -604,11 +578,7 @@ func (a *Account) call(to types.Address, data types.Data, gaslimit types.GasLimi
a.Nonce(),
)

res, err := a.fch.executeAndHandleCall(ctx, call, nil, false)
if err != nil {
return nil, err
}
return res.ReturnedValue, nil
return a.fch.executeAndHandleCall(ctx, call, nil, false)
}

func (a *Account) precheck(authroized bool, gaslimit types.GasLimit) (types.BlockContext, error) {
Expand Down
Loading

0 comments on commit 48ffcdd

Please sign in to comment.