diff --git a/contracts/wasm/testwasmlib/test/deploy.cmd b/contracts/wasm/testwasmlib/test/deploy.cmd index a4581d2a8a..46aedaf353 100644 --- a/contracts/wasm/testwasmlib/test/deploy.cmd +++ b/contracts/wasm/testwasmlib/test/deploy.cmd @@ -8,5 +8,4 @@ wasp-cli chain deploy-contract wasmtime testwasmlib "Test WasmLib" ..\rs\testwas wasp-cli chain post-request -s testwasmlib random wasp-cli chain call-view testwasmlib getRandom | wasp-cli decode string random uint64 wasp-cli chain balance -wasp-cli chain list-accounts wasp-cli check-versions diff --git a/contracts/wasm/testwasmlib/test/deploy.sh b/contracts/wasm/testwasmlib/test/deploy.sh index f6222f50e5..e6aa74b1cd 100644 --- a/contracts/wasm/testwasmlib/test/deploy.sh +++ b/contracts/wasm/testwasmlib/test/deploy.sh @@ -9,5 +9,4 @@ wasp-cli chain deploy-contract wasmtime testwasmlib "Test WasmLib" ../rs/testwas wasp-cli chain post-request -s testwasmlib random wasp-cli chain call-view testwasmlib getRandom | wasp-cli decode string random uint64 wasp-cli chain balance -wasp-cli chain list-accounts wasp-cli check-versions diff --git a/packages/evm/evmtest/ISCTest.sol b/packages/evm/evmtest/ISCTest.sol index c49416514d..30c7bb424a 100644 --- a/packages/evm/evmtest/ISCTest.sol +++ b/packages/evm/evmtest/ISCTest.sol @@ -247,7 +247,6 @@ contract ISCTest { ISCAssets memory allowance; allowance.baseTokens = 100000; - // TODO why does this not work correctly (importing via ISCTypes) ISCAgentID memory agentID = ISCTypes.newL1AgentID(l1addr); ISCDict memory params = ISCDict(new ISCDictItem[](3)); diff --git a/packages/isc/irc27nft.go b/packages/isc/irc27nft.go index 38b1400800..7de1524a3e 100644 --- a/packages/isc/irc27nft.go +++ b/packages/isc/irc27nft.go @@ -24,7 +24,7 @@ func NewIRC27NFTMetadata(mimeType, uri, name, attributes string) *IRC27NFTMetada MIMEType: mimeType, URI: uri, Name: name, - Attributes: attributes, // TODO validate that attributes are a valid JSON? + Attributes: attributes, } } diff --git a/packages/testutil/testdbhash/TestDeployNativeContract-root.hex b/packages/testutil/testdbhash/TestDeployNativeContract-root.hex index 90c3887609..ca90a02879 100644 --- a/packages/testutil/testdbhash/TestDeployNativeContract-root.hex +++ b/packages/testutil/testdbhash/TestDeployNativeContract-root.hex @@ -1 +1 @@ -0x4fccfa68bb2a25bbb54e65796a0fb4a7ee2cdb82dd9b5cede2f9674c5b474209 +0x97abe1b6193673f6c561c704ef04565b1211e344ffdf44eae0ca4b93e2b39bb4 diff --git a/packages/testutil/testdbhash/TestGetEvents-blocklog.hex b/packages/testutil/testdbhash/TestGetEvents-blocklog.hex index 84d80aa60c..f38755de38 100644 --- a/packages/testutil/testdbhash/TestGetEvents-blocklog.hex +++ b/packages/testutil/testdbhash/TestGetEvents-blocklog.hex @@ -1 +1 @@ -0xf44bb465759a04e6942e716bfcd8652f6afb2c1dbcb1fdf6bf77d9129f07f0f8 +0x6d23c7af0d1d75bccf5d2132d94466f685ff7dfcdf568ce9426e24f3f72329b9 diff --git a/packages/testutil/testdbhash/TestNFTMint-mint_to_self,_then_mint_from_it_as_a_collection1-accounts.hex b/packages/testutil/testdbhash/TestNFTMint-mint_to_self,_then_mint_from_it_as_a_collection1-accounts.hex index 6ffedbda60..8306a2f6c0 100644 --- a/packages/testutil/testdbhash/TestNFTMint-mint_to_self,_then_mint_from_it_as_a_collection1-accounts.hex +++ b/packages/testutil/testdbhash/TestNFTMint-mint_to_self,_then_mint_from_it_as_a_collection1-accounts.hex @@ -1 +1 @@ -0xdbcc902a05b06563da0b687d9d73689b63e83fee57309ecb37fc151b9121aa1e +0xf48358eea8a78e3ea311ee6b8c67cf664fa1df7411c2dbb7d86875dd9ed40d2b diff --git a/packages/testutil/testdbhash/TestNFTMint-mint_to_self,_then_mint_from_it_as_a_collection2-accounts.hex b/packages/testutil/testdbhash/TestNFTMint-mint_to_self,_then_mint_from_it_as_a_collection2-accounts.hex index 9917ce94fd..6176ea3ccb 100644 --- a/packages/testutil/testdbhash/TestNFTMint-mint_to_self,_then_mint_from_it_as_a_collection2-accounts.hex +++ b/packages/testutil/testdbhash/TestNFTMint-mint_to_self,_then_mint_from_it_as_a_collection2-accounts.hex @@ -1 +1 @@ -0x33699eeaa2c59b8cc13b997c79697f991515b78baeafabc51c318666a160ab4b +0x6e3f35b3f5a6b14f9001d42c1b8dd78c676a238af8202b3fb2c9b3fdecbefd01 diff --git a/packages/testutil/testdbhash/TestSelfDestruct-evm.hex b/packages/testutil/testdbhash/TestSelfDestruct-evm.hex index 9f9fbbdbbe..038f119121 100644 --- a/packages/testutil/testdbhash/TestSelfDestruct-evm.hex +++ b/packages/testutil/testdbhash/TestSelfDestruct-evm.hex @@ -1 +1 @@ -0x11cacd5ff64036c943c1882fb7186f141232237c145313f9befcddbac77b7ca2 +0x6ff8ffff5befa3c4cf2bd6f14b492611a977c2abc83f8e5ba2088de7c2e16d12 diff --git a/packages/testutil/testdbhash/TestSendBaseTokens-evm.hex b/packages/testutil/testdbhash/TestSendBaseTokens-evm.hex index 57dd649a06..de875ef42b 100644 --- a/packages/testutil/testdbhash/TestSendBaseTokens-evm.hex +++ b/packages/testutil/testdbhash/TestSendBaseTokens-evm.hex @@ -1 +1 @@ -0x5835faf7e10d35e126af3b13d000fa5d5b100a5ae329a1d50b9ab47b937787ce +0x29f7a125c10e0d3a49c7b697c54627910235b826b55c8cb3706167b94757a315 diff --git a/packages/testutil/testdbhash/TestStorageContract-evm.hex b/packages/testutil/testdbhash/TestStorageContract-evm.hex index 07216fe0bc..846975483b 100644 --- a/packages/testutil/testdbhash/TestStorageContract-evm.hex +++ b/packages/testutil/testdbhash/TestStorageContract-evm.hex @@ -1 +1 @@ -0xf947695a32a4a3bd1a33c878a39f37f3db4e8cffb98b60d9c10ac38af1703cf5 +0x5d36d9fd395239fd2bcad1bb313ba3b653ca58a50a85b479ef2fcf5cef24bf7d diff --git a/packages/testutil/testdbhash/TestUnprocessableWithPruning-blocklog.hex b/packages/testutil/testdbhash/TestUnprocessableWithPruning-blocklog.hex index 28d3128661..e2aefd4632 100644 --- a/packages/testutil/testdbhash/TestUnprocessableWithPruning-blocklog.hex +++ b/packages/testutil/testdbhash/TestUnprocessableWithPruning-blocklog.hex @@ -1 +1 @@ -0x316e88b911b69e241d916ab7f98f0ec1301c22eec5a1ba559c720742a6d8587b +0xff156b18e625b1a3d2ebfa7d749515c6b3ada0aa20fd7bb5ee3d14f4d2f6e18f diff --git a/packages/vm/core/evm/emulator/emulator.go b/packages/vm/core/evm/emulator/emulator.go index 4b42226d50..d2b2c002cf 100644 --- a/packages/vm/core/evm/emulator/emulator.go +++ b/packages/vm/core/evm/emulator/emulator.go @@ -122,7 +122,7 @@ func Init( chainID uint16, gasLimits GasLimits, timestamp uint64, - alloc core.GenesisAlloc, + alloc types.GenesisAlloc, ) { bdb := NewBlockchainDB(emulatorState, gasLimits.Block, BlockKeepAll) if bdb.Initialized() { diff --git a/packages/vm/core/evm/evmimpl/impl.go b/packages/vm/core/evm/evmimpl/impl.go index befdd8812c..2ae1c618c9 100644 --- a/packages/vm/core/evm/evmimpl/impl.go +++ b/packages/vm/core/evm/evmimpl/impl.go @@ -54,10 +54,10 @@ var Processor = evm.Contract.Processor(nil, // block on a newly created ISC chain. func SetInitialState(evmPartition kv.KVStore, evmChainID uint16, createBaseTokenMagicWrap bool) { // Ethereum genesis block configuration - genesisAlloc := core.GenesisAlloc{} + genesisAlloc := types.GenesisAlloc{} // add the ISC magic contract at address 0x10740000...00 - genesisAlloc[iscmagic.Address] = core.GenesisAccount{ + genesisAlloc[iscmagic.Address] = types.Account{ // Dummy code, because some contracts check the code size before calling // the contract. // The EVM code itself will never get executed; see type [magicContract]. @@ -68,7 +68,7 @@ func SetInitialState(evmPartition kv.KVStore, evmChainID uint16, createBaseToken if createBaseTokenMagicWrap { // add the ERC20BaseTokens contract at address 0x10740100...00 - genesisAlloc[iscmagic.ERC20BaseTokensAddress] = core.GenesisAccount{ + genesisAlloc[iscmagic.ERC20BaseTokensAddress] = types.Account{ Code: iscmagic.ERC20BaseTokensRuntimeBytecode, Storage: map[common.Hash]common.Hash{}, Balance: nil, @@ -77,7 +77,7 @@ func SetInitialState(evmPartition kv.KVStore, evmChainID uint16, createBaseToken } // add the ERC721NFTs contract at address 0x10740300...00 - genesisAlloc[iscmagic.ERC721NFTsAddress] = core.GenesisAccount{ + genesisAlloc[iscmagic.ERC721NFTsAddress] = types.Account{ Code: iscmagic.ERC721NFTsRuntimeBytecode, Storage: map[common.Hash]common.Hash{}, Balance: nil, @@ -440,23 +440,23 @@ func newL1Deposit(ctx isc.Sandbox) dict.Dict { ctx.RequireCaller(isc.NewContractAgentID(ctx.ChainID(), accounts.Contract.Hname())) params := ctx.Params() l1DepositOriginatorBytes := params.MustGetBytes(evm.FieldAgentIDDepositOriginator) - fromAddress := common.Address{} toAddress := common.BytesToAddress(params.MustGetBytes(evm.FieldAddress)) assets, err := isc.AssetsFromBytes(params.MustGetBytes(evm.FieldAssets)) ctx.RequireNoError(err, "unable to parse assets from params") txData := l1DepositOriginatorBytes // create a fake tx so that the operation is visible by the EVM - addDummyTxWithTransferEvents(ctx, fromAddress, toAddress, assets, txData) + addDummyTxWithTransferEvents(ctx, toAddress, assets, txData) return nil } func addDummyTxWithTransferEvents( ctx isc.Sandbox, - fromAddress, toAddress common.Address, + toAddress common.Address, assets *isc.Assets, txData []byte, ) { - logs := makeTransferEvents(ctx, fromAddress, toAddress, assets) + zeroAddress := common.Address{} + logs := makeTransferEvents(ctx, zeroAddress, toAddress, assets) wei := util.BaseTokensDecimalsToEthereumDecimals(assets.BaseTokens, newEmulatorContext(ctx).BaseTokensDecimals()) if wei.Sign() == 0 && len(logs) == 0 { diff --git a/packages/vm/core/evm/evmtest/evm_test.go b/packages/vm/core/evm/evmtest/evm_test.go index 4c2730375a..437e7f2cef 100644 --- a/packages/vm/core/evm/evmtest/evm_test.go +++ b/packages/vm/core/evm/evmtest/evm_test.go @@ -500,14 +500,19 @@ func TestISCNFTMint(t *testing.T) { ethKey, ethAddr := env.Chain.NewEthereumAccountWithL2Funds() iscTest := env.deployISCTestContract(ethKey) - _, err := iscTest.CallFn([]ethCallOptions{{ - value: big.NewInt(int64(5000000000000 * isc.Million)), - }}, "mintNFT") - - require.NoError(t, err) + var mintID []byte + iscTest.CallFnExpectEvent( + []ethCallOptions{{ + value: big.NewInt(int64(5000000000000 * isc.Million)), + }}, + "nftMint", + &mintID, + "mintNFT", + ) + require.NotEmpty(t, mintID) /// produce a block (so the minted nft gets accounted for) - _, err = iscTest.triggerEvent("Hi from EVM!") + _, err := iscTest.triggerEvent("Hi from EVM!") require.NoError(t, err) /// diff --git a/packages/vm/core/migrations/allmigrations/all.go b/packages/vm/core/migrations/allmigrations/all.go index 5fd3ccc490..737aa83a2e 100644 --- a/packages/vm/core/migrations/allmigrations/all.go +++ b/packages/vm/core/migrations/allmigrations/all.go @@ -3,6 +3,7 @@ package allmigrations import ( "github.com/iotaledger/wasp/packages/vm/core/migrations" "github.com/iotaledger/wasp/packages/vm/core/migrations/m001" + "github.com/iotaledger/wasp/packages/vm/core/migrations/m002" ) var DefaultScheme = &migrations.MigrationScheme{ @@ -17,5 +18,6 @@ var DefaultScheme = &migrations.MigrationScheme{ // BaseSchemaVersion by one. Migrations: []migrations.Migration{ m001.AccountDecimals, + m002.UpdateEVMISCMagic, }, } diff --git a/packages/vm/core/migrations/m002/update_iscmagic.go b/packages/vm/core/migrations/m002/update_iscmagic.go new file mode 100644 index 0000000000..958791579b --- /dev/null +++ b/packages/vm/core/migrations/m002/update_iscmagic.go @@ -0,0 +1,22 @@ +package m002 + +import ( + "github.com/iotaledger/hive.go/logger" + "github.com/iotaledger/wasp/packages/kv" + "github.com/iotaledger/wasp/packages/kv/subrealm" + "github.com/iotaledger/wasp/packages/vm/core/evm" + "github.com/iotaledger/wasp/packages/vm/core/evm/emulator" + "github.com/iotaledger/wasp/packages/vm/core/evm/iscmagic" + "github.com/iotaledger/wasp/packages/vm/core/migrations" +) + +var UpdateEVMISCMagic = migrations.Migration{ + Contract: evm.Contract, + Apply: func(state kv.KVStore, log *logger.Logger) error { + evmPartition := subrealm.New(state, kv.Key(evm.Contract.Hname().Bytes())) + emulatorState := evm.EmulatorStateSubrealm(evmPartition) + stateDBSubrealm := emulator.StateDBSubrealm(emulatorState) + emulator.SetCode(stateDBSubrealm, iscmagic.ERC721NFTsAddress, iscmagic.ERC721NFTsRuntimeBytecode) + return nil + }, +} diff --git a/tools/cluster/tests/wasp-cli_test.go b/tools/cluster/tests/wasp-cli_test.go index 6f519dfa76..c3a7665d2f 100644 --- a/tools/cluster/tests/wasp-cli_test.go +++ b/tools/cluster/tests/wasp-cli_test.go @@ -25,7 +25,6 @@ import ( "github.com/iotaledger/wasp/packages/parameters" "github.com/iotaledger/wasp/packages/testutil/testkey" "github.com/iotaledger/wasp/packages/vm/core/accounts" - "github.com/iotaledger/wasp/packages/vm/core/blob" "github.com/iotaledger/wasp/packages/vm/core/blocklog" "github.com/iotaledger/wasp/packages/vm/gas" "github.com/iotaledger/wasp/packages/vm/vmtypes" @@ -96,62 +95,6 @@ func TestZeroGasFee(t *testing.T) { }) } -func TestWaspCLI1Chain(t *testing.T) { - w := newWaspCLITest(t) - - chainName := "chain1" - - committee, quorum := w.ArgCommitteeConfig(0) - - // test chain deploy command - w.MustRun("chain", "deploy", "--chain="+chainName, committee, quorum, "--evm-chainid=1091", "--block-keep-amount=123", "--node=0") - w.ActivateChainOnAllNodes(chainName, 0) - - // test chain info command - chainID := w.ChainID(0) - - require.NotEmpty(t, chainID) - t.Logf("Chain ID: %s", chainID) - - // test chain list command - out := w.MustRun("chain", "list", "--node=0") - require.Contains(t, out[0], "Total 1 chain(s)") - require.Contains(t, out[4], chainID) - - // test chain list-contracts command - out = w.MustRun("chain", "list-contracts", "--node=0") - require.Regexp(t, `Total \d+ contracts in chain .{64}`, out[0]) - - // test chain list-accounts command - out = w.MustRun("chain", "list-accounts", "--node=0") - require.Contains(t, out[0], "Total 1 account(s)") - agentID := strings.TrimSpace(out[4]) - require.NotEmpty(t, agentID) - t.Logf("Agent ID: %s", agentID) - - // test chain balance command - out = w.MustRun("chain", "balance", agentID, "--node=0") - // check that the chain balance of owner is > 0 - r := regexp.MustCompile(`(?m)base\s+(\d+)$`).FindStringSubmatch(out[len(out)-1]) - require.Len(t, r, 2) - bal, err := strconv.ParseInt(r[1], 10, 64) - require.NoError(t, err) - require.Positive(t, bal) - - // same test, this time calling the view function manually - out = w.MustRun("chain", "call-view", "accounts", "balance", "string", "a", "agentid", agentID, "--node=0") - out = w.MustPipe(out, "decode", "bytes", "bigint") - - r = regexp.MustCompile(`(?m):\s+(\d+)$`).FindStringSubmatch(out[0]) - bal2, err := strconv.ParseInt(r[1], 10, 64) - require.NoError(t, err) - require.EqualValues(t, bal, bal2) - - // test the chainlog - out = w.MustRun("chain", "events", "root", "--node=0") - require.Len(t, out, 1) -} - func checkBalance(t *testing.T, out []string, expected int) { t.Helper() // regex example: base tokens 1000000 @@ -536,46 +479,6 @@ func TestWaspCLIBlockLog(t *testing.T) { require.True(t, found) } -func TestWaspCLIBlobContract(t *testing.T) { - w := newWaspCLITest(t) - - committee, quorum := w.ArgCommitteeConfig(0) - w.MustRun("chain", "deploy", "--chain=chain1", committee, quorum, "--node=0") - w.ActivateChainOnAllNodes("chain1", 0) - - // for running off-ledger requests - w.MustRun("chain", "deposit", "base:10", "--node=0") - - // test chain list-blobs command - out := w.MustRun("chain", "list-blobs", "--node=0") - require.Contains(t, out[0], "Total 0 blob(s)") - - vmtype := vmtypes.WasmTime - description := "inccounter SC" - w.CopyFile(srcFile) - - // test chain store-blob command - w.MustRun( - "chain", "store-blob", - "string", blob.VarFieldProgramBinary, "file", file, - "string", blob.VarFieldVMType, "string", vmtype, - "string", blob.VarFieldProgramDescription, "string", description, - "--node=0", - ) - - out = w.MustRun("chain", "list-blobs", "--node=0") - require.Contains(t, out[0], "Total 1 blob(s)") - - blobHash := regexp.MustCompile(`(?m)([[:alnum:]]+)\s`).FindStringSubmatch(out[4])[1] - require.NotEmpty(t, blobHash) - t.Logf("Blob hash: %s", blobHash) - - // test chain show-blob command - out = w.MustRun("chain", "show-blob", blobHash, "--node=0") - out = w.MustPipe(out, "decode", "string", blob.VarFieldProgramDescription, "string") - require.Contains(t, out[0], description) -} - func TestWaspCLIRejoinChain(t *testing.T) { w := newWaspCLITest(t)