Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Flow EVM] reducing the scope of deposit to COAs only #5280

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions fvm/evm/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: [],
Expand Down
14 changes: 4 additions & 10 deletions fvm/evm/stdlib/contract.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

Comment on lines -19 to -27
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also update the FLIP to reflect this change, both in the Cadence code, and also by adding a line or two that explains the rational (can just copy the description of the linked issue).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the FLIP is updated with changes on the Cadence code side but I'll add a small explainer why its only available on the COAs.

/// Balance of the address
access(all)
fun balance(): Balance {
Expand Down Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions fvm/evm/stdlib/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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
}
`)

Expand Down Expand Up @@ -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
Expand Down
Loading