From 29db56b1239bb1b512d94bdd4601dafb7284b30f Mon Sep 17 00:00:00 2001 From: Francisco Tobar Date: Thu, 5 Sep 2024 11:06:37 -0600 Subject: [PATCH] fix: nonce from worker signer --- package.json | 4 ++-- src/gasEstimator/gasEstimator.ts | 13 +++++++++++-- test/gasEstimator/gasEstimator.test.ts | 14 +++++++++++++- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 1015812..ac7d17f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@rsksmart/rif-relay-client", - "version": "2.2.5", + "version": "2.2.6", "private": false, "description": "This project contains all the client code for the rif relay system.", "license": "MIT", @@ -90,7 +90,7 @@ "typescript": "4.8.2" }, "peerDependencies": { - "@rsksmart/rif-relay-contracts": "2.1.1-beta.1", + "@rsksmart/rif-relay-contracts": "2.1.1-beta.2", "ethers": "^5.7.0" }, "publishConfig": { diff --git a/src/gasEstimator/gasEstimator.ts b/src/gasEstimator/gasEstimator.ts index 0901aa6..3a7d8ea 100644 --- a/src/gasEstimator/gasEstimator.ts +++ b/src/gasEstimator/gasEstimator.ts @@ -14,7 +14,10 @@ import { type EnvelopingRequest, type RelayTxOptions, } from '../common'; -import { RelayHub__factory } from '@rsksmart/rif-relay-contracts'; +import { + BaseSmartWalletFactory__factory, + RelayHub__factory, +} from '@rsksmart/rif-relay-contracts'; import { signEnvelopingRequest } from '../signer'; const estimateRelayMaxPossibleGas = async ( @@ -96,18 +99,24 @@ const estimateRelayMaxPossibleGasNoSignature = async ( const isDeploy = isDeployRequest(relayRequest); if (isDeploy) { const from = signer.address; + const provider = getProvider(); + const factory = BaseSmartWalletFactory__factory.connect( + await relayRequest.relayData.callForwarder, + provider + ); + const nonce = factory.nonce(from); const updatedRelayRequest = { request: { ...relayRequest.request, from, to: constants.AddressZero, + nonce, }, relayData: { ...relayRequest.relayData, }, }; const signature = signEnvelopingRequest(updatedRelayRequest, from, signer); - const provider = getProvider(); const relayHub = RelayHub__factory.connect( await request.relayHub, provider diff --git a/test/gasEstimator/gasEstimator.test.ts b/test/gasEstimator/gasEstimator.test.ts index 95bd685..05d1340 100644 --- a/test/gasEstimator/gasEstimator.test.ts +++ b/test/gasEstimator/gasEstimator.test.ts @@ -3,7 +3,12 @@ import chaiAsPromised from 'chai-as-promised'; import sinonChai from 'sinon-chai'; import { createSandbox, SinonStubbedInstance } from 'sinon'; import { BigNumber, constants, providers, Wallet } from 'ethers'; -import { RelayHub, RelayHub__factory } from '@rsksmart/rif-relay-contracts'; +import { + BaseSmartWalletFactory__factory, + RelayHub, + RelayHub__factory, + SmartWalletFactory, +} from '@rsksmart/rif-relay-contracts'; import { FAKE_DEPLOY_REQUEST, @@ -300,7 +305,14 @@ describe('GasEstimator', function () { }, } as unknown as RelayHub; + const factoryStub = { + nonce: () => Promise.resolve(constants.One), + } as unknown as SmartWalletFactory; + sandbox.stub(RelayHub__factory, 'connect').returns(relayHubStub); + sandbox + .stub(BaseSmartWalletFactory__factory, 'connect') + .returns(factoryStub); }); describe('with contract execution', function () {