From e893b21aee2244865c73c4748f261061e3cb40b9 Mon Sep 17 00:00:00 2001 From: ramtinms Date: Tue, 23 Jan 2024 23:00:57 -0800 Subject: [PATCH] reduce the scope of deposit to COAs only --- fvm/evm/evm_test.go | 11 +++++------ fvm/evm/stdlib/contract.cdc | 14 ++++---------- fvm/evm/stdlib/contract_test.go | 11 +++++------ 3 files changed, 14 insertions(+), 22 deletions(-) diff --git a/fvm/evm/evm_test.go b/fvm/evm/evm_test.go index 927fdc76d2f..acd0a3c8289 100644 --- a/fvm/evm/evm_test.go +++ b/fvm/evm/evm_test.go @@ -138,10 +138,9 @@ func TestEVMAddressDeposit(t *testing.T) { let vault <- minter.mintTokens(amount: 1.23) destroy minter - let address = EVM.EVMAddress( - bytes: [2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] - ) - address.deposit(from: <-vault) + let bridgedAccount <- EVM.createBridgedAccount() + bridgedAccount.deposit(from: <-vault) + destroy bridgedAccount } `, sc.EVMContract.Address.HexWithPrefix(), @@ -195,7 +194,7 @@ func TestBridgedAccountWithdraw(t *testing.T) { destroy minter let bridgedAccount <- EVM.createBridgedAccount() - bridgedAccount.address().deposit(from: <-vault) + bridgedAccount.deposit(from: <-vault) let vault2 <- bridgedAccount.withdraw(balance: EVM.Balance(flow: 1.23)) let balance = vault2.balance @@ -254,7 +253,7 @@ func TestBridgedAccountDeploy(t *testing.T) { destroy minter let bridgedAccount <- EVM.createBridgedAccount() - bridgedAccount.address().deposit(from: <-vault) + bridgedAccount.deposit(from: <-vault) let address = bridgedAccount.deploy( code: [], diff --git a/fvm/evm/stdlib/contract.cdc b/fvm/evm/stdlib/contract.cdc index e8946f214cf..3151542131b 100644 --- a/fvm/evm/stdlib/contract.cdc +++ b/fvm/evm/stdlib/contract.cdc @@ -16,15 +16,6 @@ contract EVM { self.bytes = bytes } - /// Deposits the given vault into the EVM account with the given address - access(all) - fun deposit(from: @FlowToken.Vault) { - InternalEVM.deposit( - from: <-from, - to: self.bytes - ) - } - /// Balance of the address access(all) fun balance(): Balance { @@ -81,7 +72,10 @@ contract EVM { /// Deposits the given vault into the bridged account's balance access(all) fun deposit(from: @FlowToken.Vault) { - self.address().deposit(from: <-from) + InternalEVM.deposit( + from: <-from, + to: self.addressBytes + ) } /// Withdraws the balance from the bridged account's balance diff --git a/fvm/evm/stdlib/contract_test.go b/fvm/evm/stdlib/contract_test.go index 4e4ad1c9b06..0e75a8b3da8 100644 --- a/fvm/evm/stdlib/contract_test.go +++ b/fvm/evm/stdlib/contract_test.go @@ -3075,7 +3075,7 @@ func TestEVMAddressDeposit(t *testing.T) { handler := &testContractHandler{ accountByAddress: func(fromAddress types.Address, isAuthorized bool) types.Account { - assert.Equal(t, types.Address{2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, fromAddress) + assert.Equal(t, types.Address{1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, fromAddress) assert.False(t, isAuthorized) return &testFlowAccount{ @@ -3111,10 +3111,9 @@ func TestEVMAddressDeposit(t *testing.T) { let vault <- minter.mintTokens(amount: 1.23) destroy minter - let address = EVM.EVMAddress( - bytes: [2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] - ) - address.deposit(from: <-vault) + let bridgedAccount <- EVM.createBridgedAccount() + bridgedAccount.deposit(from: <-vault) + destroy bridgedAccount } `) @@ -3236,7 +3235,7 @@ func TestBridgedAccountWithdraw(t *testing.T) { destroy minter let bridgedAccount <- EVM.createBridgedAccount() - bridgedAccount.address().deposit(from: <-vault) + bridgedAccount.deposit(from: <-vault) let vault2 <- bridgedAccount.withdraw(balance: EVM.Balance(flow: 1.23)) let balance = vault2.balance