nim-ethers/testmodule/testContracts.nim

29 lines
859 B
Nim
Raw Normal View History

2022-01-20 11:56:18 +00:00
import pkg/asynctest
import pkg/stint
import pkg/ethers
import ./hardhat
type
2022-01-20 13:00:28 +00:00
Erc20* = ref object of Contract
2022-01-20 11:56:18 +00:00
TestToken = ref object of Erc20
2022-01-20 13:00:28 +00:00
method totalSupply*(erc20: Erc20): UInt256 {.base, contract.}
method balanceOf*(erc20: Erc20, account: Address): UInt256 {.base, contract.}
method allowance*(erc20: Erc20, owner, spender: Address): UInt256 {.base, contract.}
2022-01-20 11:56:18 +00:00
suite "Contracts":
var token: TestToken
var provider: JsonRpcProvider
setup:
provider = JsonRpcProvider.new()
let deployment = readDeployment()
token = TestToken.new(!deployment.address(TestToken), provider)
test "can call view methods":
let accounts = await provider.listAccounts()
check (await token.totalSupply()) == 0.u256
check (await token.balanceOf(accounts[0])) == 0.u256
check (await token.allowance(accounts[0], accounts[1])) == 0.u256