Skip to content

Commit

Permalink
update ERC721NFTs code migration
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgemmsilva committed Jul 1, 2024
1 parent 54bc3e4 commit 42a77ad
Show file tree
Hide file tree
Showing 18 changed files with 53 additions and 124 deletions.
1 change: 0 additions & 1 deletion contracts/wasm/testwasmlib/test/deploy.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion contracts/wasm/testwasmlib/test/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 0 additions & 1 deletion packages/evm/evmtest/ISCTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion packages/isc/irc27nft.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0x4fccfa68bb2a25bbb54e65796a0fb4a7ee2cdb82dd9b5cede2f9674c5b474209
0x97abe1b6193673f6c561c704ef04565b1211e344ffdf44eae0ca4b93e2b39bb4
2 changes: 1 addition & 1 deletion packages/testutil/testdbhash/TestGetEvents-blocklog.hex
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0xf44bb465759a04e6942e716bfcd8652f6afb2c1dbcb1fdf6bf77d9129f07f0f8
0x6d23c7af0d1d75bccf5d2132d94466f685ff7dfcdf568ce9426e24f3f72329b9
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0xdbcc902a05b06563da0b687d9d73689b63e83fee57309ecb37fc151b9121aa1e
0xf48358eea8a78e3ea311ee6b8c67cf664fa1df7411c2dbb7d86875dd9ed40d2b
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0x33699eeaa2c59b8cc13b997c79697f991515b78baeafabc51c318666a160ab4b
0x6e3f35b3f5a6b14f9001d42c1b8dd78c676a238af8202b3fb2c9b3fdecbefd01
2 changes: 1 addition & 1 deletion packages/testutil/testdbhash/TestSelfDestruct-evm.hex
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0x11cacd5ff64036c943c1882fb7186f141232237c145313f9befcddbac77b7ca2
0x6ff8ffff5befa3c4cf2bd6f14b492611a977c2abc83f8e5ba2088de7c2e16d12
2 changes: 1 addition & 1 deletion packages/testutil/testdbhash/TestSendBaseTokens-evm.hex
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0x5835faf7e10d35e126af3b13d000fa5d5b100a5ae329a1d50b9ab47b937787ce
0x29f7a125c10e0d3a49c7b697c54627910235b826b55c8cb3706167b94757a315
2 changes: 1 addition & 1 deletion packages/testutil/testdbhash/TestStorageContract-evm.hex
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0xf947695a32a4a3bd1a33c878a39f37f3db4e8cffb98b60d9c10ac38af1703cf5
0x5d36d9fd395239fd2bcad1bb313ba3b653ca58a50a85b479ef2fcf5cef24bf7d
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0x316e88b911b69e241d916ab7f98f0ec1301c22eec5a1ba559c720742a6d8587b
0xff156b18e625b1a3d2ebfa7d749515c6b3ada0aa20fd7bb5ee3d14f4d2f6e18f
2 changes: 1 addition & 1 deletion packages/vm/core/evm/emulator/emulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
16 changes: 8 additions & 8 deletions packages/vm/core/evm/evmimpl/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
17 changes: 11 additions & 6 deletions packages/vm/core/evm/evmtest/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
///

Expand Down
2 changes: 2 additions & 0 deletions packages/vm/core/migrations/allmigrations/all.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -17,5 +18,6 @@ var DefaultScheme = &migrations.MigrationScheme{
// BaseSchemaVersion by one.
Migrations: []migrations.Migration{
m001.AccountDecimals,
m002.UpdateEVMISCMagic,
},
}
22 changes: 22 additions & 0 deletions packages/vm/core/migrations/m002/update_iscmagic.go
Original file line number Diff line number Diff line change
@@ -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
},
}
97 changes: 0 additions & 97 deletions tools/cluster/tests/wasp-cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 42a77ad

Please sign in to comment.