Skip to content

Commit

Permalink
restructure wiki-howtos
Browse files Browse the repository at this point in the history
  • Loading branch information
salaheldinsoliman committed Jul 5, 2024
1 parent 0274236 commit c312b1b
Showing 1 changed file with 0 additions and 89 deletions.
89 changes: 0 additions & 89 deletions packages/vm/core/evm/evmtest/evm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/ethereum/go-ethereum/eth/tracers"
"github.com/ethereum/go-ethereum/rpc"
"github.com/samber/lo"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

iotago "github.com/iotaledger/iota.go/v3"
Expand Down Expand Up @@ -2730,91 +2729,3 @@ func TestDisableMagicWrap(t *testing.T) {
envWithMagicWrap := InitEVM(t, true)
require.NotNil(t, envWithMagicWrap.getCode(envWithMagicWrap.ERC20BaseTokens(nil).address))
}

func TestBaseBalance(t *testing.T) {
env := InitEVMWithSolo(t, solo.New(t), true)
privateKey, deployer := env.Chain.NewEthereumAccountWithL2Funds()

instance := env.DeployContract(privateKey, evmtest.GetBalanceContractABI, evmtest.GetBalanceContractBytecode)

balance, _ := env.Chain.EVM().Balance(deployer, nil)
decimals := env.Chain.EVM().BaseToken().Decimals
var value uint64
instance.CallFnExpectEvent(nil, "GotBaseBalance", &value, "getBalanceBaseTokens")
realBalance := util.BaseTokensDecimalsToEthereumDecimals(value, decimals)
assert.Equal(t, balance, realBalance)
}

func TestNativeBalance(t *testing.T) {
env := InitEVMWithSolo(t, solo.New(t), true)
privateKey, deployer := env.Chain.NewEthereumAccountWithL2Funds()

instance := env.DeployContract(privateKey, evmtest.GetBalanceContractABI, evmtest.GetBalanceContractBytecode)

// create a new native token on L1
foundry, tokenID, err := env.Chain.NewNativeTokenParams(100000000000000).CreateFoundry()
require.NoError(t, err)
// the token id in bytes, used to call the contract
nativeTokenIDBytes := isc.NativeTokenIDToBytes(tokenID)

// mint some native tokens to the chain originator
err = env.Chain.MintTokens(foundry, 10000000, env.Chain.OriginatorPrivateKey)
require.NoError(t, err)

// get the agentId of the contract deployer
senderAgentID := isc.NewEthereumAddressAgentID(env.Chain.ChainID, deployer)

// send some native tokens to the contract deployer
// and check if the balance returned by the contract is correct
err = env.Chain.SendFromL2ToL2AccountNativeTokens(tokenID, senderAgentID, 100000, env.Chain.OriginatorPrivateKey)
require.NoError(t, err)

nativeBalance := new(big.Int)
instance.CallFnExpectEvent(nil, "GotNativeTokenBalance", &nativeBalance, "getBalanceNativeTokens", nativeTokenIDBytes)
assert.Equal(t, int64(100000), nativeBalance.Int64())
}

func TestNFTBalance(t *testing.T) {
env := InitEVMWithSolo(t, solo.New(t), true)
privateKey, deployer := env.Chain.NewEthereumAccountWithL2Funds()

instance := env.DeployContract(privateKey, evmtest.GetBalanceContractABI, evmtest.GetBalanceContractBytecode)

// get the agentId of the contract deployer
senderAgentID := isc.NewEthereumAddressAgentID(env.Chain.ChainID, deployer)

// mint an NFToken to the contract deployer
// and check if the balance returned by the contract is correct
mockMetaData := []byte("sesa")
nfti, info, err := env.Chain.Env.MintNFTL1(env.Chain.OriginatorPrivateKey, env.Chain.OriginatorAddress, mockMetaData)
require.NoError(t, err)
env.Chain.MustDepositNFT(nfti, env.Chain.OriginatorAgentID, env.Chain.OriginatorPrivateKey)

transfer := isc.NewEmptyAssets()
transfer.AddNFTs(info.NFTID)

// send the NFT to the contract deployer
err = env.Chain.SendFromL2ToL2Account(transfer, senderAgentID, env.Chain.OriginatorPrivateKey)
require.NoError(t, err)

// get the NFT balance of the contract deployer
nftBalance := new(big.Int)
instance.CallFnExpectEvent(nil, "GotNFTIDs", &nftBalance, "getBalanceNFTs")
assert.Equal(t, int64(1), nftBalance.Int64())
}

func TestAgentID(t *testing.T) {
env := InitEVMWithSolo(t, solo.New(t), true)
privateKey, deployer := env.Chain.NewEthereumAccountWithL2Funds()

instance := env.DeployContract(privateKey, evmtest.GetBalanceContractABI, evmtest.GetBalanceContractBytecode)

// get the agentId of the contract deployer
senderAgentID := isc.NewEthereumAddressAgentID(env.Chain.ChainID, deployer)

// get the agnetId of the contract deployer
// and compare it with the agentId returned by the contract
var agentID []byte
instance.CallFnExpectEvent(nil, "GotAgentID", &agentID, "getAgentID")
assert.Equal(t, senderAgentID.Bytes(), agentID)
}

0 comments on commit c312b1b

Please sign in to comment.