Skip to content

Commit

Permalink
Merge pull request onflow#5294 from onflow/janez/set-evm-storage-acco…
Browse files Browse the repository at this point in the history
…unts

Set the correct testnet/mainnet evm state storage account
  • Loading branch information
janezpodhostnik authored Jan 29, 2024
2 parents 90d626e + 2ead409 commit 7bb57e9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
10 changes: 9 additions & 1 deletion fvm/fvm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3163,7 +3163,15 @@ func TestEVM(t *testing.T) {
)

t.Run("deploy contract code", newVMTest().
withBootstrapProcedureOptions(fvm.WithSetupEVMEnabled(true)).
withBootstrapProcedureOptions(
fvm.WithSetupEVMEnabled(true),
).
withContextOptions(
// default is testnet, but testnet has a special EVM storage contract location
// so we have to use emulator here so that the EVM storage contract is deployed
// to the 5th address
fvm.WithChain(flow.Emulator.Chain()),
).
run(func(
t *testing.T,
vm fvm.VM,
Expand Down
18 changes: 17 additions & 1 deletion fvm/systemcontracts/system_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ var (
nftTokenAddressMainnet = flow.HexToAddress("1d7e57aa55817448")
// nftTokenAddressTestnet is the address of the NonFungibleToken contract on Testnet
nftTokenAddressTestnet = flow.HexToAddress("631e88ae7f1d7c20")

// evmStorageAddressTestnet is the address of the EVM state storage contract on Testnet
evmStorageAddressTestnet = flow.HexToAddress("1a54ed2be7552821")
// evmStorageAddressMainnet is the address of the EVM state storage contract on Mainnet
evmStorageAddressMainnet = flow.HexToAddress("d421a63faae318f9")
)

// SystemContract represents a system contract on a particular chain.
Expand Down Expand Up @@ -284,6 +289,17 @@ func init() {
}
}

evmStorageEVMFunc := func(chain flow.ChainID) flow.Address {
switch chain {
case flow.Mainnet:
return evmStorageAddressMainnet
case flow.Testnet:
return evmStorageAddressTestnet
default:
return nthAddressFunc(EVMStorageAccountIndex)(chain)
}
}

contractAddressFunc = map[string]func(id flow.ChainID) flow.Address{
ContractNameIDTableStaking: epochAddressFunc,
ContractNameEpoch: epochAddressFunc,
Expand All @@ -304,7 +320,7 @@ func init() {
ContractNameViewResolver: nftTokenAddressFunc,

ContractNameEVM: serviceAddressFunc,
AccountNameEVMStorage: nthAddressFunc(EVMStorageAccountIndex),
AccountNameEVMStorage: evmStorageEVMFunc,
}

getSystemContractsForChain := func(chainID flow.ChainID) *SystemContracts {
Expand Down

0 comments on commit 7bb57e9

Please sign in to comment.