From 69f90a3d67e7a897c300ef10935c3563c802c9c3 Mon Sep 17 00:00:00 2001 From: Eric <5089238+emizzle@users.noreply.github.com> Date: Fri, 2 Feb 2024 16:31:01 +1100 Subject: [PATCH] fix: specify raises for getAddress and sendTransaction Fixes issue where getAddress and sendTransaction could not be found for MockSigner in tests. The problem was that the async: raises update had not been applied to the MockSigner. --- ethers/providers/jsonrpc.nim | 5 +++-- ethers/signer.nim | 4 ++-- ethers/signers/wallet.nim | 7 +++++-- testmodule/mocks.nim | 12 ++++++++---- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/ethers/providers/jsonrpc.nim b/ethers/providers/jsonrpc.nim index 2cc37b5..3e097db 100644 --- a/ethers/providers/jsonrpc.nim +++ b/ethers/providers/jsonrpc.nim @@ -301,7 +301,7 @@ method provider*(signer: JsonRpcSigner): Provider {.gcsafe, raises: [SignerError signer.provider method getAddress*( - signer: JsonRpcSigner): Future[Address] {.async.} = + signer: JsonRpcSigner): Future[Address] {.async: (raises:[SignerError]).} = if address =? signer.address: return address @@ -324,7 +324,8 @@ method signMessage*( method sendTransaction*( signer: JsonRpcSigner, - transaction: Transaction): Future[TransactionResponse] {.async.} = + transaction: Transaction): Future[TransactionResponse] + {.async: (raises:[SignerError]).} = convertSignerError: if nonce =? transaction.nonce: diff --git a/ethers/signer.nim b/ethers/signer.nim index df05eba..3a70dc7 100644 --- a/ethers/signer.nim +++ b/ethers/signer.nim @@ -40,7 +40,7 @@ method provider*( doAssert false, "not implemented" method getAddress*( - signer: Signer): Future[Address] {.base, async.} = + signer: Signer): Future[Address] {.base, async: (raises:[SignerError]).} = doAssert false, "not implemented" @@ -53,7 +53,7 @@ method signMessage*( method sendTransaction*( signer: Signer, transaction: Transaction): Future[TransactionResponse] - {.base, async.} = + {.base, async: (raises:[SignerError]).} = doAssert false, "not implemented" diff --git a/ethers/signers/wallet.nim b/ethers/signers/wallet.nim index c622c21..d757b62 100644 --- a/ethers/signers/wallet.nim +++ b/ethers/signers/wallet.nim @@ -67,7 +67,9 @@ method provider*(wallet: Wallet): Provider {.gcsafe, raises: [SignerError].} = raiseWalletError "Wallet has no provider" provider -method getAddress*(wallet: Wallet): Future[Address] {.async.} = +method getAddress*( + wallet: Wallet): Future[Address] {.async: (raises:[SignerError]).} = + return wallet.address proc signTransaction*(wallet: Wallet, @@ -79,7 +81,8 @@ proc signTransaction*(wallet: Wallet, method sendTransaction*( wallet: Wallet, - transaction: Transaction): Future[TransactionResponse] {.async.} = + transaction: Transaction): Future[TransactionResponse] + {.async: (raises:[SignerError]).} = convertError: let signed = await signTransaction(wallet, transaction) diff --git a/testmodule/mocks.nim b/testmodule/mocks.nim index 30584e1..7e3d877 100644 --- a/testmodule/mocks.nim +++ b/testmodule/mocks.nim @@ -11,10 +11,14 @@ func new*(_: type MockSigner, provider: Provider): MockSigner = method provider*(signer: MockSigner): Provider = signer.provider -method getAddress*(signer: MockSigner): Future[Address] {.async.} = +method getAddress*( + signer: MockSigner): Future[Address] {.async: (raises:[SignerError]).} = + return signer.address -method sendTransaction*(signer: MockSigner, - transaction: Transaction): - Future[TransactionResponse] {.async.} = +method sendTransaction*( + signer: MockSigner, + transaction: Transaction): Future[TransactionResponse] + {.async: (raises:[SignerError]).} = + signer.transactions.add(transaction)