fix: eth_call use signers address (#43)
This commit is contained in:
parent
5a4f786757
commit
18e225607c
|
@ -7,7 +7,7 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
nim: [1.2.16, stable]
|
nim: [1.6.12, stable]
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
|
@ -3,6 +3,7 @@ author = "Nim Ethers Authors"
|
||||||
description = "library for interacting with Ethereum"
|
description = "library for interacting with Ethereum"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
||||||
|
requires "nim >= 1.6.0"
|
||||||
requires "chronos >= 3.0.0 & < 4.0.0"
|
requires "chronos >= 3.0.0 & < 4.0.0"
|
||||||
requires "contractabi >= 0.4.6 & < 0.5.0"
|
requires "contractabi >= 0.4.6 & < 0.5.0"
|
||||||
requires "questionable >= 0.10.2 & < 0.11.0"
|
requires "questionable >= 0.10.2 & < 0.11.0"
|
||||||
|
|
|
@ -93,7 +93,11 @@ proc call(contract: Contract,
|
||||||
function: string,
|
function: string,
|
||||||
parameters: tuple,
|
parameters: tuple,
|
||||||
overrides = TransactionOverrides()) {.async.} =
|
overrides = TransactionOverrides()) {.async.} =
|
||||||
let transaction = createTransaction(contract, function, parameters, overrides)
|
var transaction = createTransaction(contract, function, parameters, overrides)
|
||||||
|
|
||||||
|
if signer =? contract.signer and transaction.sender.isNone:
|
||||||
|
transaction.sender = some(await signer.getAddress())
|
||||||
|
|
||||||
discard await contract.provider.call(transaction, overrides)
|
discard await contract.provider.call(transaction, overrides)
|
||||||
|
|
||||||
proc call(contract: Contract,
|
proc call(contract: Contract,
|
||||||
|
@ -102,7 +106,11 @@ proc call(contract: Contract,
|
||||||
ReturnType: type,
|
ReturnType: type,
|
||||||
returnMultiple: static bool,
|
returnMultiple: static bool,
|
||||||
overrides = TransactionOverrides()): Future[ReturnType] {.async.} =
|
overrides = TransactionOverrides()): Future[ReturnType] {.async.} =
|
||||||
let transaction = createTransaction(contract, function, parameters, overrides)
|
var transaction = createTransaction(contract, function, parameters, overrides)
|
||||||
|
|
||||||
|
if signer =? contract.signer and transaction.sender.isNone:
|
||||||
|
transaction.sender = some(await signer.getAddress())
|
||||||
|
|
||||||
let response = await contract.provider.call(transaction, overrides)
|
let response = await contract.provider.call(transaction, overrides)
|
||||||
return decodeResponse(ReturnType, returnMultiple, response)
|
return decodeResponse(ReturnType, returnMultiple, response)
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ type
|
||||||
TestToken = ref object of Erc20Token
|
TestToken = ref object of Erc20Token
|
||||||
|
|
||||||
method mint(token: TestToken, holder: Address, amount: UInt256): ?TransactionResponse {.base, contract.}
|
method mint(token: TestToken, holder: Address, amount: UInt256): ?TransactionResponse {.base, contract.}
|
||||||
|
method myBalance(token: TestToken): UInt256 {.contract, view.}
|
||||||
|
|
||||||
suite "Contracts":
|
suite "Contracts":
|
||||||
|
|
||||||
|
@ -43,6 +44,13 @@ suite "Contracts":
|
||||||
check (await token.totalSupply()) == 100.u256
|
check (await token.totalSupply()) == 100.u256
|
||||||
check (await token.balanceOf(accounts[1])) == 100.u256
|
check (await token.balanceOf(accounts[1])) == 100.u256
|
||||||
|
|
||||||
|
test "can call constant functions with a signer and the account is used for the call":
|
||||||
|
let signer0 = provider.getSigner(accounts[0])
|
||||||
|
let signer1 = provider.getSigner(accounts[1])
|
||||||
|
discard await token.connect(signer0).mint(accounts[1], 100.u256)
|
||||||
|
check (await token.connect(signer0).myBalance()) == 0.u256
|
||||||
|
check (await token.connect(signer1).myBalance()) == 100.u256
|
||||||
|
|
||||||
test "can call non-constant functions without a signer":
|
test "can call non-constant functions without a signer":
|
||||||
discard await token.mint(accounts[1], 100.u256)
|
discard await token.mint(accounts[1], 100.u256)
|
||||||
check (await token.balanceOf(accounts[1])) == 0.u256
|
check (await token.balanceOf(accounts[1])) == 0.u256
|
||||||
|
|
|
@ -17,4 +17,8 @@ contract TestToken is ERC20 {
|
||||||
function burn(address holder, uint amount) public {
|
function burn(address holder, uint amount) public {
|
||||||
_burn(holder, amount);
|
_burn(holder, amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function myBalance() public view returns (uint256) {
|
||||||
|
return balanceOf(msg.sender);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue