Skip to content

Commit

Permalink
fix: nonce from worker signer
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscotobar committed Sep 5, 2024
1 parent 63b84fe commit 29db56b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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": {
Expand Down
13 changes: 11 additions & 2 deletions src/gasEstimator/gasEstimator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion test/gasEstimator/gasEstimator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 () {
Expand Down

0 comments on commit 29db56b

Please sign in to comment.