Add Contract.connect()
This commit is contained in:
parent
1e767b2107
commit
9eee20e49d
|
@ -25,6 +25,9 @@ func new*(ContractType: type Contract,
|
||||||
signer: Signer): ContractType =
|
signer: Signer): ContractType =
|
||||||
ContractType(signer: some signer, provider: signer.provider, address: address)
|
ContractType(signer: some signer, provider: signer.provider, address: address)
|
||||||
|
|
||||||
|
func connect*[T: Contract](contract: T, provider: Provider | Signer): T =
|
||||||
|
T.new(contract.address, provider)
|
||||||
|
|
||||||
func provider*(contract: Contract): Provider =
|
func provider*(contract: Contract): Provider =
|
||||||
contract.provider
|
contract.provider
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ type
|
||||||
method totalSupply*(erc20: Erc20): UInt256 {.base, contract, view.}
|
method totalSupply*(erc20: Erc20): UInt256 {.base, contract, view.}
|
||||||
method balanceOf*(erc20: Erc20, account: Address): UInt256 {.base, contract, view.}
|
method balanceOf*(erc20: Erc20, account: Address): UInt256 {.base, contract, view.}
|
||||||
method allowance*(erc20: Erc20, owner, spender: Address): UInt256 {.base, contract, view.}
|
method allowance*(erc20: Erc20, owner, spender: Address): UInt256 {.base, contract, view.}
|
||||||
|
method transfer*(erc20: Erc20, recipient: Address, amount: UInt256) {.base, contract.}
|
||||||
|
|
||||||
method mint(token: TestToken, holder: Address, amount: UInt256) {.base, contract.}
|
method mint(token: TestToken, holder: Address, amount: UInt256) {.base, contract.}
|
||||||
|
|
||||||
|
@ -66,3 +67,13 @@ suite "Contracts":
|
||||||
let works = compiles:
|
let works = compiles:
|
||||||
proc foo(token: TestToken, bar: Address): UInt256 {.contract.}
|
proc foo(token: TestToken, bar: Address): UInt256 {.contract.}
|
||||||
check not works
|
check not works
|
||||||
|
|
||||||
|
test "can connect to different providers and signers":
|
||||||
|
let signer0 = provider.getSigner(accounts[0])
|
||||||
|
let signer1 = provider.getSigner(accounts[1])
|
||||||
|
await token.connect(signer0).mint(accounts[0], 100.u256)
|
||||||
|
await token.connect(signer0).transfer(accounts[1], 50.u256)
|
||||||
|
await token.connect(signer1).transfer(accounts[2], 25.u256)
|
||||||
|
check (await token.connect(provider).balanceOf(accounts[0])) == 50.u256
|
||||||
|
check (await token.connect(provider).balanceOf(accounts[1])) == 25.u256
|
||||||
|
check (await token.connect(provider).balanceOf(accounts[2])) == 25.u256
|
||||||
|
|
Loading…
Reference in New Issue