Skip to content

Commit

Permalink
MCOPY opcode error demo
Browse files Browse the repository at this point in the history
Signed-off-by: salaheldinsoliman <[email protected]>
  • Loading branch information
salaheldinsoliman committed Jun 18, 2024
1 parent 0230f99 commit eb65f67
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 87 deletions.
28 changes: 28 additions & 0 deletions documentation/tutorial-examples/solidity/GetBalance.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.0;

import "./node_modules/@iota/iscmagic/ISC.sol";

contract GetBalance {
event GotAgentID(bytes agentID);
event GotBaseBalance(uint64 baseBalance);
event GotNativeTokenBalance(uint256 nativeTokenBalance);
event GotNFTIDs(uint256 nftBalance);

function getBalance(bytes memory nativeTokenID) public {
ISCAgentID memory agentID = ISC.sandbox.getSenderAccount();
emit GotAgentID(agentID.data);

uint64 baseBalance = ISC.accounts.getL2BalanceBaseTokens(agentID);
emit GotBaseBalance(baseBalance);

NativeTokenID memory id = NativeTokenID({ data: nativeTokenID});
uint256 nativeTokens = ISC.accounts.getL2BalanceNativeTokens(id, agentID);
emit GotNativeTokenBalance(nativeTokens);

uint256 nfts = ISC.accounts.getL2NFTAmount(agentID);
emit GotNativeTokenBalance(nfts);

}
}
35 changes: 0 additions & 35 deletions documentation/tutorial-examples/solidity/NativeTokenBalance.sol

This file was deleted.

62 changes: 62 additions & 0 deletions documentation/tutorial-examples/solidity/get_balance_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package solidity_test

import (
_ "embed"
"math/big"
"strings"
"testing"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/iotaledger/wasp/packages/solo"
)

// compile the solidity contract

//go:generate solc --abi --bin --overwrite GetBalance.sol -o .
var (
//go:embed GetBalance.abi
GetBalanceContractABI string
//go:embed GetBalance.bin
GetBalanceContractBytecodeHex string
GetBalanceContractBytecode = common.FromHex(strings.TrimSpace(GetBalanceContractBytecodeHex))
)

func TestGetBalance(t *testing.T) {
env := solo.New(t)
chain := env.NewChain()

chainID, chainOwnerID, _ := chain.GetInfo()

t.Log("chainID: ", chainID.String())
t.Log("chain owner ID: ", chainOwnerID.String())

private_key, user_address := chain.NewEthereumAccountWithL2Funds()

t.Log("Address of the userWallet is: ", private_key)

t.Log("Address of the userWallet1 is: ", user_address)

contract_addr, abi := chain.DeployEVMContract(private_key, GetBalanceContractABI, GetBalanceContractBytecode, &big.Int{})

serial, token_id, err := chain.NewNativeTokenParams(1000000000).CreateFoundry()

t.Log("Contract address: ", serial)
t.Log("Contract address: ", token_id)
t.Log("Contract address: ", err)

callArgs, err := abi.Pack("getBalance", []byte(token_id.ToHex()))
callMsg := ethereum.CallMsg{
To: &contract_addr,
Data: callArgs,
}

t.Log("Err: ", err)

result, err := chain.EVM().CallContract(callMsg, nil)

t.Log("Result: ", result)

t.Log("contract err: ", err)

}
52 changes: 0 additions & 52 deletions documentation/tutorial-examples/solidity/simple_test.go

This file was deleted.

0 comments on commit eb65f67

Please sign in to comment.