Skip to content

Commit

Permalink
Merge pull request #4872 from onflow/ramtin/evm-add-dummy-kitty-contract
Browse files Browse the repository at this point in the history
[FVM] beyond EVM part 7 - adding more evm-based contract types for testing
  • Loading branch information
ramtinms authored Nov 15, 2023
2 parents aad2f84 + 3eab0d8 commit c1ec969
Show file tree
Hide file tree
Showing 7 changed files with 260 additions and 40 deletions.
10 changes: 5 additions & 5 deletions fvm/evm/emulator/emulator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestNativeTokenBridging(t *testing.T) {
})
})
})
t.Run("mint tokens withdraw", func(t *testing.T) {
t.Run("tokens withdraw", func(t *testing.T) {
amount := big.NewInt(1000)
RunWithNewEmulator(t, db, func(env *emulator.Emulator) {
RunWithNewReadOnlyBlockView(t, env, func(blk types.ReadOnlyBlockView) {
Expand Down Expand Up @@ -93,7 +93,7 @@ func TestNativeTokenBridging(t *testing.T) {
func TestContractInteraction(t *testing.T) {
RunWithTestDB(t, func(db types.Database) {

testContract := testutils.GetTestContract(t)
testContract := testutils.GetStorageTestContract(t)

testAccount := types.NewAddressFromString("test")
amount := big.NewInt(0).Mul(big.NewInt(1337), big.NewInt(gethParams.Ether))
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestContractInteraction(t *testing.T) {
types.NewContractCall(
testAccount,
contractAddr,
testContract.MakeStoreCallData(t, num),
testContract.MakeCallData(t, "store", num),
1_000_000,
big.NewInt(0), // this should be zero because the contract doesn't have receiver
),
Expand All @@ -164,7 +164,7 @@ func TestContractInteraction(t *testing.T) {
types.NewContractCall(
testAccount,
contractAddr,
testContract.MakeRetrieveCallData(t),
testContract.MakeCallData(t, "retrieve"),
1_000_000,
big.NewInt(0), // this should be zero because the contract doesn't have receiver
),
Expand All @@ -183,7 +183,7 @@ func TestContractInteraction(t *testing.T) {
types.NewContractCall(
testAccount,
contractAddr,
testContract.MakeBlockNumberCallData(t),
testContract.MakeCallData(t, "blockNumber"),
1_000_000,
big.NewInt(0), // this should be zero because the contract doesn't have receiver
),
Expand Down
15 changes: 9 additions & 6 deletions fvm/evm/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/onflow/flow-go/fvm"
"github.com/onflow/flow-go/fvm/evm/stdlib"
. "github.com/onflow/flow-go/fvm/evm/testutils"

"github.com/onflow/flow-go/fvm/evm/types"
"github.com/onflow/flow-go/fvm/storage/snapshot"
"github.com/onflow/flow-go/model/flow"
Expand All @@ -26,7 +25,8 @@ func TestEVMRun(t *testing.T) {
t.Run("testing EVM.run (happy case)", func(t *testing.T) {
RunWithTestBackend(t, func(backend types.Backend) {
RunWithTestFlowEVMRootAddress(t, backend, func(rootAddr flow.Address) {
RunWithDeployedContract(t, backend, rootAddr, func(testContract *TestContract) {
tc := GetStorageTestContract(t)
RunWithDeployedContract(t, tc, backend, rootAddr, func(testContract *TestContract) {
RunWithEOATestAccount(t, backend, rootAddr, func(testAccount *EOATestAccount) {
num := int64(12)
chain := flow.Emulator.Chain()
Expand All @@ -49,7 +49,7 @@ func TestEVMRun(t *testing.T) {

txBytes := testAccount.PrepareSignAndEncodeTx(t,
testContract.DeployedAt.ToCommon(),
testContract.MakeStoreCallData(t, big.NewInt(num)),
testContract.MakeCallData(t, "store", big.NewInt(num)),
big.NewInt(0),
gasLimit,
big.NewInt(0),
Expand Down Expand Up @@ -115,7 +115,8 @@ func TestEVMAddressDeposit(t *testing.T) {

RunWithTestBackend(t, func(backend types.Backend) {
RunWithTestFlowEVMRootAddress(t, backend, func(rootAddr flow.Address) {
RunWithDeployedContract(t, backend, rootAddr, func(testContract *TestContract) {
tc := GetStorageTestContract(t)
RunWithDeployedContract(t, tc, backend, rootAddr, func(testContract *TestContract) {
RunWithEOATestAccount(t, backend, rootAddr, func(testAccount *EOATestAccount) {
chain := flow.Emulator.Chain()
RunWithNewTestVM(t, chain, func(ctx fvm.Context, vm fvm.VM, snapshot snapshot.SnapshotTree) {
Expand Down Expand Up @@ -167,7 +168,8 @@ func TestBridgedAccountWithdraw(t *testing.T) {

RunWithTestBackend(t, func(backend types.Backend) {
RunWithTestFlowEVMRootAddress(t, backend, func(rootAddr flow.Address) {
RunWithDeployedContract(t, backend, rootAddr, func(testContract *TestContract) {
tc := GetStorageTestContract(t)
RunWithDeployedContract(t, tc, backend, rootAddr, func(testContract *TestContract) {
RunWithEOATestAccount(t, backend, rootAddr, func(testAccount *EOATestAccount) {
chain := flow.Emulator.Chain()
RunWithNewTestVM(t, chain, func(ctx fvm.Context, vm fvm.VM, snapshot snapshot.SnapshotTree) {
Expand Down Expand Up @@ -225,7 +227,8 @@ func TestBridgedAccountDeploy(t *testing.T) {

RunWithTestBackend(t, func(backend types.Backend) {
RunWithTestFlowEVMRootAddress(t, backend, func(rootAddr flow.Address) {
RunWithDeployedContract(t, backend, rootAddr, func(testContract *TestContract) {
tc := GetStorageTestContract(t)
RunWithDeployedContract(t, tc, backend, rootAddr, func(testContract *TestContract) {
RunWithEOATestAccount(t, backend, rootAddr, func(testAccount *EOATestAccount) {
chain := flow.Emulator.Chain()
RunWithNewTestVM(t, chain, func(ctx fvm.Context, vm fvm.VM, snapshot snapshot.SnapshotTree) {
Expand Down
6 changes: 3 additions & 3 deletions fvm/evm/handler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,21 +517,21 @@ func TestHandler_BridgedAccount(t *testing.T) {
vault := types.NewFlowTokenVault(orgBalance)
foa.Deposit(vault)

testContract := testutils.GetTestContract(t)
testContract := testutils.GetStorageTestContract(t)
addr := foa.Deploy(testContract.ByteCode, math.MaxUint64, types.Balance(0))
require.NotNil(t, addr)

num := big.NewInt(22)

_ = foa.Call(
addr,
testContract.MakeStoreCallData(t, num),
testContract.MakeCallData(t, "store", num),
math.MaxUint64,
types.Balance(0))

ret := foa.Call(
addr,
testContract.MakeRetrieveCallData(t),
testContract.MakeCallData(t, "retrieve"),
math.MaxUint64,
types.Balance(0))

Expand Down
Loading

0 comments on commit c1ec969

Please sign in to comment.