-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2eaefc7
commit 0274236
Showing
4 changed files
with
116 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"anonymous":false,"inputs":[{"indexed":false,"internalType":"bytes","name":"agentID","type":"bytes"}],"name":"GotAgentID","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"baseBalance","type":"uint64"}],"name":"GotBaseBalance","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"nftBalance","type":"uint256"}],"name":"GotNFTIDs","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"nativeTokenBalance","type":"uint256"}],"name":"GotNativeTokenBalance","type":"event"},{"inputs":[],"name":"getAgentID","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getBalanceBaseTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"getBalanceNFTs","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"nativeTokenID","type":"bytes"}],"name":"getBalanceNativeTokens","outputs":[],"stateMutability":"nonpayable","type":"function"}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
608060405234801561000f575f80fd5b50610acc8061001d5f395ff3fe608060405234801561000f575f80fd5b506004361061004a575f3560e01c806319a5506a1461004e57806341d9834c1461005857806390cdadcd14610074578063cdfd0a661461007e575b5f80fd5b610056610088565b005b610072600480360381019061006d91906106a2565b6101d9565b005b61007c610340565b005b610086610404565b005b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa1580156100e5573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061010d91906107dc565b90505f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16630d90ec7b836040518263ffffffff1660e01b815260040161015d919061089c565b602060405180830381865afa158015610178573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061019c91906108ef565b90507f52c249d568f18754049ea99591153f1f0ad8c7ab03a3bcdcf8454bc274e54101816040516101cd9190610929565b60405180910390a15050565b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa158015610236573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061025e91906107dc565b90505f60405180602001604052808481525090505f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663ef43e40d83856040518363ffffffff1660e01b81526004016102c2929190610969565b602060405180830381865afa1580156102dd573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061030191906108ef565b90507fab4abdf0d66655ed9c7e1ee2f2aff1d43dbdc0736a3e7078c2be95bcf3800575816040516103329190610929565b60405180910390a150505050565b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa15801561039d573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f820116820180604052508101906103c591906107dc565b90507f28b3d377892d8db500fb9a9bbd4731605ca2a642c3c62a7e64d47b7d42024368815f01516040516103f991906109e6565b60405180910390a150565b5f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663f31317496040518163ffffffff1660e01b81526004015f60405180830381865afa158015610461573d5f803e3d5ffd5b505050506040513d5f823e3d601f19601f8201168201806040525081019061048991906107dc565b90505f73107400000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff1663b019204f836040518263ffffffff1660e01b81526004016104d9919061089c565b602060405180830381865afa1580156104f4573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906105189190610a43565b90507f23ce6861f26687742455d6955fcd53a5587ecf279e37422d0cd9636e2a2a9f7f816040516105499190610a7d565b60405180910390a15050565b5f604051905090565b5f80fd5b5f80fd5b5f80fd5b5f80fd5b5f601f19601f8301169050919050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b6105b48261056e565b810181811067ffffffffffffffff821117156105d3576105d261057e565b5b80604052505050565b5f6105e5610555565b90506105f182826105ab565b919050565b5f67ffffffffffffffff8211156106105761060f61057e565b5b6106198261056e565b9050602081019050919050565b828183375f83830152505050565b5f610646610641846105f6565b6105dc565b9050828152602081018484840111156106625761066161056a565b5b61066d848285610626565b509392505050565b5f82601f83011261068957610688610566565b5b8135610699848260208601610634565b91505092915050565b5f602082840312156106b7576106b661055e565b5b5f82013567ffffffffffffffff8111156106d4576106d3610562565b5b6106e084828501610675565b91505092915050565b5f80fd5b5f80fd5b5f5b8381101561070e5780820151818401526020810190506106f3565b5f8484015250505050565b5f61072b610726846105f6565b6105dc565b9050828152602081018484840111156107475761074661056a565b5b6107528482856106f1565b509392505050565b5f82601f83011261076e5761076d610566565b5b815161077e848260208601610719565b91505092915050565b5f6020828403121561079c5761079b6106e9565b5b6107a660206105dc565b90505f82015167ffffffffffffffff8111156107c5576107c46106ed565b5b6107d18482850161075a565b5f8301525092915050565b5f602082840312156107f1576107f061055e565b5b5f82015167ffffffffffffffff81111561080e5761080d610562565b5b61081a84828501610787565b91505092915050565b5f81519050919050565b5f82825260208201905092915050565b5f61084782610823565b610851818561082d565b93506108618185602086016106f1565b61086a8161056e565b840191505092915050565b5f602083015f8301518482035f86015261088f828261083d565b9150508091505092915050565b5f6020820190508181035f8301526108b48184610875565b905092915050565b5f819050919050565b6108ce816108bc565b81146108d8575f80fd5b50565b5f815190506108e9816108c5565b92915050565b5f602082840312156109045761090361055e565b5b5f610911848285016108db565b91505092915050565b610923816108bc565b82525050565b5f60208201905061093c5f83018461091a565b92915050565b5f602083015f8301518482035f86015261095c828261083d565b9150508091505092915050565b5f6040820190508181035f8301526109818185610942565b905081810360208301526109958184610875565b90509392505050565b5f82825260208201905092915050565b5f6109b882610823565b6109c2818561099e565b93506109d28185602086016106f1565b6109db8161056e565b840191505092915050565b5f6020820190508181035f8301526109fe81846109ae565b905092915050565b5f67ffffffffffffffff82169050919050565b610a2281610a06565b8114610a2c575f80fd5b50565b5f81519050610a3d81610a19565b92915050565b5f60208284031215610a5857610a5761055e565b5b5f610a6584828501610a2f565b91505092915050565b610a7781610a06565b82525050565b5f602082019050610a905f830184610a6e565b9291505056fea26469706673582212202c9d1af4136de267ede721d5e5ea147744597e332cd762811459a05c0013200264736f6c63430008140033 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package wikihowtos_test | ||
|
||
import ( | ||
_ "embed" | ||
"math/big" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/iotaledger/wasp/packages/isc" | ||
"github.com/iotaledger/wasp/packages/solo" | ||
"github.com/iotaledger/wasp/packages/util" | ||
"github.com/iotaledger/wasp/packages/vm/core/evm/evmtest" | ||
) | ||
|
||
//go:generate sh -c "solc --abi --bin --overwrite @iscmagic=`realpath ../../../vm/core/evm/iscmagic` GetBalance.sol -o ." | ||
var ( | ||
//go:embed GetBalance.abi | ||
GetBalanceContractABI string | ||
//go:embed GetBalance.bin | ||
GetBalanceContractBytecodeHex string | ||
GetBalanceContractBytecode = common.FromHex(strings.TrimSpace(GetBalanceContractBytecodeHex)) | ||
) | ||
|
||
func TestBaseBalance(t *testing.T) { | ||
env := evmtest.InitEVMWithSolo(t, solo.New(t), true) | ||
privateKey, deployer := env.Chain.NewEthereumAccountWithL2Funds() | ||
|
||
instance := env.DeployContract(privateKey, GetBalanceContractABI, 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 := evmtest.InitEVMWithSolo(t, solo.New(t), true) | ||
privateKey, deployer := env.Chain.NewEthereumAccountWithL2Funds() | ||
|
||
instance := env.DeployContract(privateKey, GetBalanceContractABI, 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 := evmtest.InitEVMWithSolo(t, solo.New(t), true) | ||
privateKey, deployer := env.Chain.NewEthereumAccountWithL2Funds() | ||
|
||
instance := env.DeployContract(privateKey, GetBalanceContractABI, 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 := evmtest.InitEVMWithSolo(t, solo.New(t), true) | ||
privateKey, deployer := env.Chain.NewEthereumAccountWithL2Funds() | ||
|
||
instance := env.DeployContract(privateKey, GetBalanceContractABI, 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) | ||
} |