-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: salaheldinsoliman <[email protected]>
- Loading branch information
1 parent
0230f99
commit eb65f67
Showing
4 changed files
with
90 additions
and
87 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
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
35
documentation/tutorial-examples/solidity/NativeTokenBalance.sol
This file was deleted.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
documentation/tutorial-examples/solidity/get_balance_test.go
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,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) | ||
|
||
} |
This file was deleted.
Oops, something went wrong.