Skip to content

Commit

Permalink
Merge pull request #6106 from onflow/ramtin/6103-add-uuids-to-deposit…
Browse files Browse the repository at this point in the history
…-and-withdraw-events

[Flow EVM] add uuids to the deposit and withdraw events
  • Loading branch information
ramtinms authored Jun 21, 2024
2 parents 59d4caf + c8c6c47 commit 6db1bfd
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
2 changes: 1 addition & 1 deletion engine/execution/state/bootstrap/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestBootstrapLedger(t *testing.T) {
}

func TestBootstrapLedger_ZeroTokenSupply(t *testing.T) {
expectedStateCommitmentBytes, _ := hex.DecodeString("7cb3d30faaaab3cb402338023b3a068bc856fb788086b1212aa0f1950f24d854")
expectedStateCommitmentBytes, _ := hex.DecodeString("3fc810ac804039b7e577053a78cad4d13b58332cb52303e098d337aa87e783a5")
expectedStateCommitment, err := flow.ToStateCommitment(expectedStateCommitmentBytes)
require.NoError(t, err)

Expand Down
31 changes: 27 additions & 4 deletions fvm/evm/stdlib/contract.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,28 @@ contract EVM {
/// FLOWTokensDeposited is emitted when FLOW tokens is bridged
/// into the EVM environment. Note that this event is not emitted
/// for transfer of flow tokens between two EVM addresses.
/// Similar to the FungibleToken.Deposited event
/// this event includes a depositedUUID that captures the
/// uuid of the source vault.
access(all)
event FLOWTokensDeposited(address: String, amount: UFix64)
event FLOWTokensDeposited(
address: String,
amount: UFix64,
depositedUUID: UInt64
)

/// FLOWTokensWithdrawn is emitted when FLOW tokens are bridged
/// out of the EVM environment. Note that this event is not emitted
/// for transfer of flow tokens between two EVM addresses.
/// similar to the FungibleToken.Withdrawn events
/// this event includes a withdrawnUUID that captures the
/// uuid of the returning vault.
access(all)
event FLOWTokensWithdrawn(address: String, amount: UFix64)
event FLOWTokensWithdrawn(
address: String,
amount: UFix64,
withdrawnUUID: UInt64
)

/// BridgeAccessorUpdated is emitted when the BridgeAccessor Capability
/// is updated in the stored BridgeRouter along with identifying
Expand Down Expand Up @@ -152,11 +166,16 @@ contract EVM {
if amount == 0.0 {
panic("calling deposit function with an empty vault is not allowed")
}
let depositedUUID = from.uuid
InternalEVM.deposit(
from: <-from,
to: self.bytes
)
emit FLOWTokensDeposited(address: self.toString(), amount: amount)
emit FLOWTokensDeposited(
address: self.toString(),
amount: amount,
depositedUUID: depositedUUID
)
}

/// Serializes the address to a hex string without the 0x prefix
Expand Down Expand Up @@ -383,7 +402,11 @@ contract EVM {
from: self.addressBytes,
amount: balance.attoflow
) as! @FlowToken.Vault
emit FLOWTokensWithdrawn(address: self.address().toString(), amount: balance.inFLOW())
emit FLOWTokensWithdrawn(
address: self.address().toString(),
amount: balance.inFLOW(),
withdrawnUUID: vault.uuid
)
return <-vault
}

Expand Down
16 changes: 16 additions & 0 deletions fvm/evm/stdlib/contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3834,6 +3834,14 @@ func TestCOADeposit(t *testing.T) {
expectedBalance,
tokenDepositEventFields["amount"],
)

// check depositedUUID, based on the transaction content
// its expected the uuid of 4 be allocated to the source vault.
expectedDepositedUUID := cadence.UInt64(4)
require.Equal(t,
expectedDepositedUUID,
tokenDepositEventFields["depositedUUID"],
)
}

func TestCadenceOwnedAccountWithdraw(t *testing.T) {
Expand Down Expand Up @@ -4004,6 +4012,14 @@ func TestCadenceOwnedAccountWithdraw(t *testing.T) {
expectedWithdrawBalance,
tokenWithdrawEventFields["amount"],
)

// check expectedWithdrawnUUID
// last allocated UUID is 1
expectedWithdrawnUUID := cadence.UInt64(1)
require.Equal(t,
expectedWithdrawnUUID,
tokenWithdrawEventFields["withdrawnUUID"],
)
}

func TestCadenceOwnedAccountDeploy(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions utils/unittest/execution_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const ServiceAccountPrivateKeySignAlgo = crypto.ECDSAP256
const ServiceAccountPrivateKeyHashAlgo = hash.SHA2_256

// Pre-calculated state commitment with root account with the above private key
const GenesisStateCommitmentHex = "ede86048a53464cdd3cef060e5e2e1603d91c2d2a0568417501af5ca9455f430"
const GenesisStateCommitmentHex = "49ad25e5716c2e302bc7ec833a19c6f6ad53823a97b4d80d1258445a150b6848"

var GenesisStateCommitment flow.StateCommitment

Expand Down Expand Up @@ -87,10 +87,10 @@ func genesisCommitHexByChainID(chainID flow.ChainID) string {
return GenesisStateCommitmentHex
}
if chainID == flow.Testnet {
return "ac9887d488bc90e33ce97478ca3f59c69795ed66061cf68d60d518be2fa0b658"
return "bc384ae96ee4105df764e810ac6e350b0edb12e346df2ec18939ebbb8cbbd9ce"
}
if chainID == flow.Sandboxnet {
return "e1c08b17f9e5896f03fe28dd37ca396c19b26628161506924fbf785834646ea1"
}
return "eb6a5749ba1a4bd9ef5b3aa804b123e0d257f68735867e661b1a1418b26f9229"
return "fc262bee4ca8a75e857dd17801b209828d5b0a306735f7219719cd64e6a39ba8"
}

0 comments on commit 6db1bfd

Please sign in to comment.