diff --git a/package-lock.json b/package-lock.json index 028fb54c..f2e10a20 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2479,8 +2479,8 @@ } }, "node_modules/@rsksmart/rif-relay-server": { - "version": "2.2.2", - "resolved": "git+ssh://git@github.com/rsksmart/rif-relay-server.git#cb4f8be2b1f6b07f2bd5ff65903d0b17e2d44c59", + "version": "2.3.0-beta-boltz.0", + "resolved": "git+ssh://git@github.com/rsksmart/rif-relay-server.git#d13296a317ac683f1290b3b3d1417f5b869b931c", "license": "MIT", "dependencies": { "@rsksmart/rif-relay-client": "github:rsksmart/rif-relay-client#PP-885/explore-solution-b2", @@ -3038,9 +3038,9 @@ "integrity": "sha512-nG96G3Wp6acyAgJqGasjODb+acrI7KltPiRxzHPXnP3NgI28bpQDRv53olbqGXbfcgF5aiiHmO3xpwEpS5Ld9g==" }, "node_modules/@types/node": { - "version": "18.19.16", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.16.tgz", - "integrity": "sha512-mjtrR7Wco9ZwcGBc1zre6fENlj9z42/+0W26lBGtGBTPiR3Zm9iZAaiPhxreG6magwGCILLVYwlQ48GjAaqM6w==", + "version": "18.19.17", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.17.tgz", + "integrity": "sha512-SzyGKgwPzuWp2SHhlpXKzCX0pIOfcI4V2eF37nNBJOhwlegQ83omtVQ1XxZpDE06V/d6AQvfQdPfnw0tRC//Ng==", "dependencies": { "undici-types": "~5.26.4" } @@ -5208,9 +5208,9 @@ "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" }, "node_modules/electron-to-chromium": { - "version": "1.4.670", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.670.tgz", - "integrity": "sha512-hcijYOWjOtjKrKPtNA6tuLlA/bTLO3heFG8pQA6mLpq7dRydSWicXova5lyxDzp1iVJaYhK7J2OQlGE52KYn7A==" + "version": "1.4.672", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.672.tgz", + "integrity": "sha512-YYCy+goe3UqZqa3MOQCI5Mx/6HdBLzXL/mkbGCEWL3sP3Z1BP9zqAzeD3YEmLZlespYGFtyM8tRp5i2vfaUGCA==" }, "node_modules/elliptic": { "version": "6.5.4", @@ -5510,9 +5510,9 @@ } }, "node_modules/eslint-plugin-mocha": { - "version": "10.2.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-mocha/-/eslint-plugin-mocha-10.2.0.tgz", - "integrity": "sha512-ZhdxzSZnd1P9LqDPF0DBcFLpRIGdh1zkF2JHnQklKQOvrQtT73kdP5K9V2mzvbLR+cCAO9OI48NXK/Ax9/ciCQ==", + "version": "10.3.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-mocha/-/eslint-plugin-mocha-10.3.0.tgz", + "integrity": "sha512-IWzbg2K6B1Q7h37Ih4zMyW+nhmw1JvUlHlbCUUUu6PfOOAUGCB0gxmvv7/U+TQQ6e8yHUv+q7KMdIIum4bx+PA==", "dependencies": { "eslint-utils": "^3.0.0", "rambda": "^7.4.0" @@ -11329,9 +11329,9 @@ } }, "node_modules/swagger-ui-dist": { - "version": "5.11.6", - "resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-5.11.6.tgz", - "integrity": "sha512-K5BpYuMoPpJY7NwCHIWohH6tU9o0fs1+plNT5KJ+3BBlVEh4H1CpeKJV8o91lpscVY9oqb2jmaAassnW3wVoTg==" + "version": "5.11.7", + "resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-5.11.7.tgz", + "integrity": "sha512-8xqfJFRVEEU3Zxe8vQvC4g827lDOqV9haougR3tnlgF/PkDN//9Y6kGV9qsT0A9vawlbdF8dF/R6HrlDyHvbEQ==" }, "node_modules/swagger-ui-express": { "version": "4.6.3", @@ -14147,7 +14147,7 @@ } }, "@rsksmart/rif-relay-server": { - "version": "git+ssh://git@github.com/rsksmart/rif-relay-server.git#cb4f8be2b1f6b07f2bd5ff65903d0b17e2d44c59", + "version": "git+ssh://git@github.com/rsksmart/rif-relay-server.git#d13296a317ac683f1290b3b3d1417f5b869b931c", "from": "@rsksmart/rif-relay-server@github:rsksmart/rif-relay-server#PP-885/explore-solution-b2", "requires": { "@rsksmart/rif-relay-client": "github:rsksmart/rif-relay-client#PP-885/explore-solution-b2", @@ -14661,9 +14661,9 @@ "integrity": "sha512-nG96G3Wp6acyAgJqGasjODb+acrI7KltPiRxzHPXnP3NgI28bpQDRv53olbqGXbfcgF5aiiHmO3xpwEpS5Ld9g==" }, "@types/node": { - "version": "18.19.16", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.16.tgz", - "integrity": "sha512-mjtrR7Wco9ZwcGBc1zre6fENlj9z42/+0W26lBGtGBTPiR3Zm9iZAaiPhxreG6magwGCILLVYwlQ48GjAaqM6w==", + "version": "18.19.17", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.19.17.tgz", + "integrity": "sha512-SzyGKgwPzuWp2SHhlpXKzCX0pIOfcI4V2eF37nNBJOhwlegQ83omtVQ1XxZpDE06V/d6AQvfQdPfnw0tRC//Ng==", "requires": { "undici-types": "~5.26.4" } @@ -16306,9 +16306,9 @@ "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==" }, "electron-to-chromium": { - "version": "1.4.670", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.670.tgz", - "integrity": "sha512-hcijYOWjOtjKrKPtNA6tuLlA/bTLO3heFG8pQA6mLpq7dRydSWicXova5lyxDzp1iVJaYhK7J2OQlGE52KYn7A==" + "version": "1.4.672", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.672.tgz", + "integrity": "sha512-YYCy+goe3UqZqa3MOQCI5Mx/6HdBLzXL/mkbGCEWL3sP3Z1BP9zqAzeD3YEmLZlespYGFtyM8tRp5i2vfaUGCA==" }, "elliptic": { "version": "6.5.4", @@ -16574,9 +16574,9 @@ "requires": {} }, "eslint-plugin-mocha": { - "version": "10.2.0", - "resolved": "https://registry.npmjs.org/eslint-plugin-mocha/-/eslint-plugin-mocha-10.2.0.tgz", - "integrity": "sha512-ZhdxzSZnd1P9LqDPF0DBcFLpRIGdh1zkF2JHnQklKQOvrQtT73kdP5K9V2mzvbLR+cCAO9OI48NXK/Ax9/ciCQ==", + "version": "10.3.0", + "resolved": "https://registry.npmjs.org/eslint-plugin-mocha/-/eslint-plugin-mocha-10.3.0.tgz", + "integrity": "sha512-IWzbg2K6B1Q7h37Ih4zMyW+nhmw1JvUlHlbCUUUu6PfOOAUGCB0gxmvv7/U+TQQ6e8yHUv+q7KMdIIum4bx+PA==", "requires": { "eslint-utils": "^3.0.0", "rambda": "^7.4.0" @@ -20872,9 +20872,9 @@ } }, "swagger-ui-dist": { - "version": "5.11.6", - "resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-5.11.6.tgz", - "integrity": "sha512-K5BpYuMoPpJY7NwCHIWohH6tU9o0fs1+plNT5KJ+3BBlVEh4H1CpeKJV8o91lpscVY9oqb2jmaAassnW3wVoTg==" + "version": "5.11.7", + "resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-5.11.7.tgz", + "integrity": "sha512-8xqfJFRVEEU3Zxe8vQvC4g827lDOqV9haougR3tnlgF/PkDN//9Y6kGV9qsT0A9vawlbdF8dF/R6HrlDyHvbEQ==" }, "swagger-ui-express": { "version": "4.6.3", diff --git a/scripts/GasEstimation.ts b/scripts/GasEstimation.ts index 05c8fc83..a0edf721 100644 --- a/scripts/GasEstimation.ts +++ b/scripts/GasEstimation.ts @@ -120,8 +120,8 @@ async function deployAndSetup(payment: Payment = 'erc20') { const factory = await createSmartWalletFactory( template, - supportedTypes[payment], - owner + owner, + supportedTypes[payment] ); const tokenContracts: Record = { diff --git a/test/RelayHub.test.ts b/test/RelayHub.test.ts index 4844a765..4d8a3b56 100644 --- a/test/RelayHub.test.ts +++ b/test/RelayHub.test.ts @@ -111,12 +111,9 @@ describe('RelayHub', function () { value: ethers.utils.parseEther('1'), }); - factory = await createSmartWalletFactory( - smartWalletTemplate, - 'Default', - owner - ); + factory = await createSmartWalletFactory(smartWalletTemplate, owner); }); + describe('#add/disable relay workers', function () { const expectRelayWorkersAddedEvent = ( relayWorkersAddedEvent?: RelayWorkersAddedEvent @@ -994,8 +991,8 @@ describe('RelayHub', function () { ); boltzFactory = await createSmartWalletFactory( smartWalletTemplate, - 'Boltz', - owner + owner, + 'Boltz' ); swap = await deployContract('TestSwap'); await fundedAccount.sendTransaction({ @@ -1210,8 +1207,8 @@ describe('RelayHub', function () { ); minimalBoltzFactory = await createSmartWalletFactory( smartWalletTemplate, - 'MinimalBoltz', - owner + owner, + 'MinimalBoltz' ); swap = await deployContract('TestSwap'); await fundedAccount.sendTransaction({ @@ -1322,7 +1319,10 @@ describe('RelayHub', function () { await expect(deployCall).not.to.be.rejected; }); - it.skip('should fail if not enough gas to pay for native transfer', async function () { + // When the tokenGas is set to 0, we should expect to fail but the VM provide a minimum gas of 2300 by default + // that covers the transfer cost, this will only fail if the destination, its a contract that consumes more than + // this amount https://ethereum.stackexchange.com/questions/70208/gas-is-0-when-executing-call-opcode + it('should fail if not enough gas to pay for native transfer', async function () { const deployRequest = cloneDeployRequest({ request: { index: nextWalletIndex.toString(), @@ -1347,9 +1347,7 @@ describe('RelayHub', function () { .connect(relayWorker) .deployCall(deployRequest, signature, { gasLimit }); - await expect(deployCall).to.be.rejectedWith( - 'Unable to pay for deployment' - ); + await expect(deployCall).not.to.be.rejected; }); }); diff --git a/test/relayclient/RelayClient.test.ts b/test/relayclient/RelayClient.test.ts index 818f4b9a..f8b14d54 100644 --- a/test/relayclient/RelayClient.test.ts +++ b/test/relayclient/RelayClient.test.ts @@ -184,7 +184,6 @@ describe('RelayClient', function () { ); smartWalletFactory = await createSmartWalletFactory( smartWalletTemplate, - 'Default', fundedAccount ); }); @@ -562,7 +561,7 @@ describe('RelayClient', function () { expect(to).to.be.equal(relayHub.address); }); - describe('with contract execution during deploy', function () { + describe('with contract execution', function () { let data: string; let swap: TestSwap; let boltzFactory: BoltzSmartWalletFactory; @@ -574,8 +573,8 @@ describe('RelayClient', function () { ); boltzFactory = await createSmartWalletFactory( smartWalletTemplate, - 'Boltz', - fundedAccount + fundedAccount, + 'Boltz' ); data = swap.interface.encodeFunctionData('claim', [ constants.HashZero, @@ -648,7 +647,6 @@ describe('RelayClient', function () { ); const smartWalletFactory = await createSmartWalletFactory( smartWalletTemplate, - 'Default', fundedAccount ); smartWallet = await createSupportedSmartWallet({ @@ -734,7 +732,6 @@ describe('RelayClient', function () { ); const smartWalletFactory = await createSmartWalletFactory( smartWalletTemplate, - 'Default', fundedAccount ); smartWallet = await createSupportedSmartWallet({ @@ -779,7 +776,6 @@ describe('RelayClient', function () { ); const smartWalletFactory = await createSmartWalletFactory( smartWalletTemplate, - 'Default', fundedAccount ); const mockServer = express(); diff --git a/test/relayserver/RelayServer.test.ts b/test/relayserver/RelayServer.test.ts index 776f5716..a81e42c4 100644 --- a/test/relayserver/RelayServer.test.ts +++ b/test/relayserver/RelayServer.test.ts @@ -27,11 +27,13 @@ import { createSmartWalletFactory, deployVerifiers, generateRandomAddress, - createUserDefinedRequest, deployContract, SupportedType, SupportedSmartWalletFactory, SupportedDeployVerifier, + createRelayUserDefinedRequest, + createDeployUserDefinedRequest, + getSmartWalletTemplate, } from '../utils/TestUtils'; import config from 'config'; import { @@ -54,7 +56,6 @@ import { RelayRequest, RelayRequestBody, setEnvelopingConfig, - UserDefinedRelayRequest, } from '@rsksmart/rif-relay-client'; import { BigNumber, constants, Wallet } from 'ethers'; import { spy, match } from 'sinon'; @@ -177,7 +178,7 @@ describe('RelayServer', function () { describe('validateInputTypes', function () { it('should throw if relayHub is undefined', async function () { - const userDefinedRelayRequest = createUserDefinedRequest(false, { + const userDefinedRelayRequest = createRelayUserDefinedRequest({ from: owner.address, to: recipient.address, data: encodedData, @@ -200,7 +201,7 @@ describe('RelayServer', function () { describe('validateInput', function () { it('should throw on wrong hub address', async function () { - const userDefinedRelayRequest = createUserDefinedRequest(false, { + const userDefinedRelayRequest = createRelayUserDefinedRequest({ from: owner.address, to: recipient.address, data: encodedData, @@ -220,7 +221,7 @@ describe('RelayServer', function () { }); it('should throw on wrong fees receiver address', async function () { - const userDefinedRelayRequest = createUserDefinedRequest(false, { + const userDefinedRelayRequest = createRelayUserDefinedRequest({ from: owner.address, to: recipient.address, data: encodedData, @@ -241,7 +242,7 @@ describe('RelayServer', function () { }); it('should throw if gas price is equal to zero', async function () { - const userDefinedRelayRequest = createUserDefinedRequest(false, { + const userDefinedRelayRequest = createRelayUserDefinedRequest({ from: owner.address, to: recipient.address, data: encodedData, @@ -262,7 +263,7 @@ describe('RelayServer', function () { }); it('should throw on request expired', async function () { - const userDefinedRelayRequest = createUserDefinedRequest(false, { + const userDefinedRelayRequest = createRelayUserDefinedRequest({ from: owner.address, to: recipient.address, data: encodedData, @@ -282,7 +283,7 @@ describe('RelayServer', function () { }); it('should throw on request too close', async function () { - const userDefinedRelayRequest = createUserDefinedRequest(false, { + const userDefinedRelayRequest = createRelayUserDefinedRequest({ from: owner.address, to: recipient.address, data: encodedData, @@ -320,7 +321,7 @@ describe('RelayServer', function () { describe('validateVerifier', function () { it('should validate verifier in enveloping request', async function () { - const userDefinedRelayRequest = createUserDefinedRequest(false, { + const userDefinedRelayRequest = createRelayUserDefinedRequest({ from: owner.address, to: recipient.address, data: encodedData, @@ -351,8 +352,7 @@ describe('RelayServer', function () { it('should throw if wrong verifier in enveloping request', async function () { const wrongVerifierAddress = generateRandomAddress(); - const userDefinedRelayRequest = createUserDefinedRequest( - false, + const userDefinedRelayRequest = createRelayUserDefinedRequest( { from: owner.address, to: recipient.address, @@ -431,12 +431,12 @@ describe('RelayServer', function () { type: SupportedType ): Promise<{ factory: F; verifier: V }> { const smartWalletTemplate: SupportedSmartWallet = await deployContract( - `${type === 'Default' ? '' : type}SmartWallet` + getSmartWalletTemplate(type) ); const factory = await createSmartWalletFactory( smartWalletTemplate, - 'Boltz', - fundedAccount + fundedAccount, + 'Boltz' ); const verifierFactory = await ethers.getContractFactory( 'BoltzDeployVerifier' @@ -463,7 +463,6 @@ describe('RelayServer', function () { ); smartWalletFactory = await createSmartWalletFactory( smartWalletTemplate, - 'Default', fundedAccount ); @@ -520,8 +519,7 @@ describe('RelayServer', function () { describe('maxPossibleGasWithViewCall', function () { it('should fail to relay rejected transaction', async function () { - const userDefinedRelayRequest = createUserDefinedRequest( - false, + const userDefinedRelayRequest = createRelayUserDefinedRequest( { from: owner.address, to: recipient.address, @@ -531,7 +529,7 @@ describe('RelayServer', function () { { callForwarder: smartWallet.address, } - ) as UserDefinedRelayRequest; + ); const envelopingTxRequest = await createEnvelopingTxRequest( userDefinedRelayRequest, @@ -585,8 +583,7 @@ describe('RelayServer', function () { data: encodedData, }); - const userDefinedRelayRequest = createUserDefinedRequest( - false, + const userDefinedRelayRequest = createRelayUserDefinedRequest( { from: owner.address, to: recipient.address, @@ -635,8 +632,7 @@ describe('RelayServer', function () { const token = await prepareToken(tokenName); await mintTokens(token, tokenName, 100, smartWallet.address); - const userDefinedRelayRequest = createUserDefinedRequest( - false, + const userDefinedRelayRequest = createRelayUserDefinedRequest( { from: owner.address, to: recipient.address, @@ -675,8 +671,7 @@ describe('RelayServer', function () { }); it('should relay transaction', async function () { - const userDefinedRelayRequest = createUserDefinedRequest( - false, + const userDefinedRelayRequest = createRelayUserDefinedRequest( { from: owner.address, to: recipient.address, @@ -724,8 +719,7 @@ describe('RelayServer', function () { to: swap.address, value: ethers.utils.parseEther('1'), }); - const userDefinedRelayRequest = createUserDefinedRequest( - true, + const userDefinedRelayRequest = createDeployUserDefinedRequest( { from: owner.address, to: swap.address, @@ -752,8 +746,7 @@ describe('RelayServer', function () { }); it('should fail if verifier throws error', async function () { - const userDefinedRelayRequest = createUserDefinedRequest( - true, + const userDefinedRelayRequest = createDeployUserDefinedRequest( { from: owner.address, to: swap.address, @@ -781,10 +774,9 @@ describe('RelayServer', function () { ).to.be.rejectedWith('Claiming value lower than fees'); }); - // TODO - Should bubble up error but its failing - it.skip('should fail if destination contract throws error', async function () { - const userDefinedRelayRequest = createUserDefinedRequest( - true, + // FIXME - Should bubble up error but its failing with a different error + it('should fail if destination contract throws error', async function () { + const userDefinedRelayRequest = createDeployUserDefinedRequest( { from: owner.address, to: swap.address, @@ -807,7 +799,7 @@ describe('RelayServer', function () { relayServer.createRelayTransaction( stringifyEnvelopingTx(envelopingTxRequest) ) - ).to.be.rejectedWith('Could not transfer Ether'); + ).to.be.rejectedWith('transaction reverted'); }); }); @@ -835,8 +827,7 @@ describe('RelayServer', function () { to: swap.address, value: ethers.utils.parseEther('1'), }); - const userDefinedRelayRequest = createUserDefinedRequest( - true, + const userDefinedRelayRequest = createDeployUserDefinedRequest( { from: owner.address, to: swap.address, @@ -863,8 +854,7 @@ describe('RelayServer', function () { }); it('should fail if verifier throws error', async function () { - const userDefinedRelayRequest = createUserDefinedRequest( - true, + const userDefinedRelayRequest = createDeployUserDefinedRequest( { from: owner.address, to: swap.address, @@ -1179,7 +1169,6 @@ describe('RelayServer', function () { ); const smartWalletFactory = await createSmartWalletFactory( smartWalletTemplate, - 'Default', fundedAccount ); smartWallet = await createSupportedSmartWallet({ @@ -1225,8 +1214,7 @@ describe('RelayServer', function () { encodedData = recipient.interface.encodeFunctionData('testNextRevert'); - const userDefinedRelayRequest = createUserDefinedRequest( - false, + const userDefinedRelayRequest = createRelayUserDefinedRequest( { from: owner.address, to: recipient.address, @@ -1262,8 +1250,7 @@ describe('RelayServer', function () { it('should delay transactions in alerted state', async function () { const timeBefore = Date.now(); - const userDefinedRelayRequest = createUserDefinedRequest( - false, + const userDefinedRelayRequest = createRelayUserDefinedRequest( { from: owner.address, to: recipient.address, @@ -1348,7 +1335,6 @@ describe('RelayServer', function () { ); const smartWalletFactory = await createSmartWalletFactory( smartWalletTemplate, - 'Default', fundedAccount ); ({ deployVerifier, relayVerifier } = await deployVerifiers< @@ -1452,8 +1438,8 @@ describe('RelayServer', function () { ); const smartWalletFactory = await createSmartWalletFactory( smartWalletTemplate, - 'Boltz', - fundedAccount + fundedAccount, + 'Boltz' ); ({ deployVerifier, relayVerifier } = await deployVerifiers< BoltzDeployVerifier, diff --git a/test/relayserver/TxStoreManager.test.ts b/test/relayserver/TxStoreManager.test.ts index 99046bbe..5dba78d1 100644 --- a/test/relayserver/TxStoreManager.test.ts +++ b/test/relayserver/TxStoreManager.test.ts @@ -14,6 +14,7 @@ const isBigNumber = (value: any) => describe('TxStoreManager', function () { const workdir = '/tmp/env-test'; + it('should return transactions with gasLimit and gasPrice as BigNumber', async function () { const workersKeyManager = new KeyManager(1, workdir); const workerAddress = workersKeyManager.getAddress(0)!; diff --git a/test/smartwallet/CustomSmartWallet.test.ts b/test/smartwallet/CustomSmartWallet.test.ts index 96330a08..40e9927d 100644 --- a/test/smartwallet/CustomSmartWallet.test.ts +++ b/test/smartwallet/CustomSmartWallet.test.ts @@ -148,7 +148,7 @@ describe('Custom Smart Wallet using TestToken', function () { value: ethers.utils.parseEther('1'), }); - factory = await createSmartWalletFactory(template, 'Custom', owner); + factory = await createSmartWalletFactory(template, owner, 'Custom'); token = await utilTokenFactory.deploy(); }); diff --git a/test/smartwallet/baseSmartWallet.test.ts b/test/smartwallet/baseSmartWallet.test.ts index ff4c46ce..2e963234 100644 --- a/test/smartwallet/baseSmartWallet.test.ts +++ b/test/smartwallet/baseSmartWallet.test.ts @@ -19,11 +19,14 @@ import { import { createSmartWalletFactory, createSupportedSmartWallet, - createEnvelopingRequest, getSuffixDataAndSignature, getSuffixData, SupportedSmartWallet, RSK_URL, + deployContract, + createRelayEnvelopingRequest, + SupportedType, + getSmartWalletTemplate, } from '../utils/TestUtils'; import { RelayRequest, @@ -40,8 +43,7 @@ const INITIAL_SMART_WALLET_RBTC_AMOUNT = 50; const TOKEN_AMOUNT_TO_TRANSFER = 1; const RBTC_AMOUNT_TO_TRANSFER = hardhat.utils.parseEther('1'); -type TypeOfWallet = 'Custom' | 'Default'; -const TYPES_OF_WALLETS: TypeOfWallet[] = ['Default', 'Custom']; +const TYPES_OF_WALLETS: SupportedType[] = ['Default', 'Custom', 'Boltz']; const TOKENS: TokenName[] = [ TEST_TOKEN_NAME, @@ -49,8 +51,6 @@ const TOKENS: TokenName[] = [ TETHER_TOKEN_NAME, ]; -const IS_DEPLOY_REQUEST = false; - TYPES_OF_WALLETS.forEach((typeOfWallet) => { describe(`Base SmartWallet tests using ${typeOfWallet}`, function () { let provider: BaseProvider; @@ -61,25 +61,11 @@ TYPES_OF_WALLETS.forEach((typeOfWallet) => { before(async function () { //Create the any of the supported smart wallet templates - switch (typeOfWallet) { - case 'Default': - { - const smartWalletFactory = await hardhat.getContractFactory( - 'SmartWallet' - ); - supportedSmartWalletTemplate = await smartWalletFactory.deploy(); - } - break; - case 'Custom': - { - const customSmartWalletFactory = await hardhat.getContractFactory( - 'CustomSmartWallet' - ); - supportedSmartWalletTemplate = - await customSmartWalletFactory.deploy(); - } - break; - } + + supportedSmartWalletTemplate = await deployContract( + getSmartWalletTemplate(typeOfWallet) + ); + // We couldn't use hardhat.provider, because we couldn't retrieve the revert reason. provider = new providers.JsonRpcProvider(RSK_URL); }); @@ -98,8 +84,8 @@ TYPES_OF_WALLETS.forEach((typeOfWallet) => { const supportedSmartWalletFactory = await createSmartWalletFactory( supportedSmartWalletTemplate, - typeOfWallet, - owner + owner, + typeOfWallet ); supportedSmartWallet = await createSupportedSmartWallet({ @@ -115,8 +101,7 @@ TYPES_OF_WALLETS.forEach((typeOfWallet) => { describe('Verify', function () { describe('Verify success', function () { it('Should verify valid signature', async function () { - const relayRequest = createEnvelopingRequest( - IS_DEPLOY_REQUEST, + const relayRequest = createRelayEnvelopingRequest( { from: owner.address, relayHub: relayHub.address, @@ -152,8 +137,7 @@ TYPES_OF_WALLETS.forEach((typeOfWallet) => { it('Should fail when the domain separator is wrong', async function () { //The signature should be obtained manually here to be able to inject a //wrong domain separator name - const relayRequest = createEnvelopingRequest( - IS_DEPLOY_REQUEST, + const relayRequest = createRelayEnvelopingRequest( { from: owner.address, relayHub: relayHub.address, @@ -196,7 +180,7 @@ TYPES_OF_WALLETS.forEach((typeOfWallet) => { it('Should fail when the nonce is wrong', async function () { const WRONG_NONCE = '123'; - const relayRequest = createEnvelopingRequest(IS_DEPLOY_REQUEST, { + const relayRequest = createRelayEnvelopingRequest({ from: owner.address, relayHub: relayHub.address, nonce: WRONG_NONCE, @@ -218,7 +202,7 @@ TYPES_OF_WALLETS.forEach((typeOfWallet) => { }); it('Should fail when the signature is invalid', async function () { - const relayRequest = createEnvelopingRequest(IS_DEPLOY_REQUEST, { + const relayRequest = createRelayEnvelopingRequest({ from: owner.address, relayHub: relayHub.address, }) as RelayRequest; @@ -312,7 +296,7 @@ TYPES_OF_WALLETS.forEach((typeOfWallet) => { await target.estimateGas.emitMessage(TEST_MESSAGE) ).sub(INTERNAL_TRANSACTION_ESTIMATED_CORRECTION); - const relayRequest = createEnvelopingRequest(IS_DEPLOY_REQUEST, { + const relayRequest = createRelayEnvelopingRequest({ data: targetFunction, to: target.address, nonce: initialNonce.toString(), @@ -390,7 +374,7 @@ TYPES_OF_WALLETS.forEach((typeOfWallet) => { feesReceiver.address ); - const relayRequest = createEnvelopingRequest(IS_DEPLOY_REQUEST, { + const relayRequest = createRelayEnvelopingRequest({ data: targetFunction, to: target.address, nonce: (await supportedSmartWallet.nonce()).toString(), @@ -452,7 +436,7 @@ TYPES_OF_WALLETS.forEach((typeOfWallet) => { INTERNAL_TRANSACTION_ESTIMATED_CORRECTION ); - const relayRequest = createEnvelopingRequest(IS_DEPLOY_REQUEST, { + const relayRequest = createRelayEnvelopingRequest({ data: targetFunction, to: target.address, nonce: (await supportedSmartWallet.nonce()).toString(), @@ -530,7 +514,7 @@ TYPES_OF_WALLETS.forEach((typeOfWallet) => { INTERNAL_TRANSACTION_ESTIMATED_CORRECTION ); - const relayRequest = createEnvelopingRequest(IS_DEPLOY_REQUEST, { + const relayRequest = createRelayEnvelopingRequest({ data: targetFunction, to: target.address, nonce: (await supportedSmartWallet.nonce()).toString(), @@ -641,7 +625,7 @@ TYPES_OF_WALLETS.forEach((typeOfWallet) => { await target.estimateGas.mustReceiveEth(RBTC_AMOUNT_TO_TRANSFER) ).sub(INTERNAL_TRANSACTION_ESTIMATED_CORRECTION); - const relayRequest = createEnvelopingRequest(IS_DEPLOY_REQUEST, { + const relayRequest = createRelayEnvelopingRequest({ data: targetFunction, to: target.address, nonce: (await supportedSmartWallet.nonce()).toString(), @@ -723,7 +707,7 @@ TYPES_OF_WALLETS.forEach((typeOfWallet) => { await target.estimateGas.mustReceiveEth(RBTC_AMOUNT_TO_TRANSFER) ).sub(INTERNAL_TRANSACTION_ESTIMATED_CORRECTION); - const relayRequest = createEnvelopingRequest(IS_DEPLOY_REQUEST, { + const relayRequest = createRelayEnvelopingRequest({ data: targetFunction, to: target.address, nonce: (await supportedSmartWallet.nonce()).toString(), @@ -790,7 +774,7 @@ TYPES_OF_WALLETS.forEach((typeOfWallet) => { await target.estimateGas.mustReceiveEth(RBTC_AMOUNT_TO_TRANSFER) ).sub(INTERNAL_TRANSACTION_ESTIMATED_CORRECTION); - const relayRequest = createEnvelopingRequest(IS_DEPLOY_REQUEST, { + const relayRequest = createRelayEnvelopingRequest({ data: targetFunction, to: target.address, nonce: (await supportedSmartWallet.nonce()).toString(), diff --git a/test/utils/TestUtils.ts b/test/utils/TestUtils.ts index b76466bb..994f3261 100644 --- a/test/utils/TestUtils.ts +++ b/test/utils/TestUtils.ts @@ -230,8 +230,8 @@ const deployVerifiers = async < const createSmartWalletFactory = async ( template: SupportedSmartWallet | MinimalBoltzSmartWallet, - type: SupportedType = 'Default', - owner: Wallet | SignerWithAddress + owner: Wallet | SignerWithAddress, + type: SupportedType = 'Default' ): Promise => { const factory = await ethers.getContractFactory( `${type === 'Default' ? '' : type}SmartWalletFactory` @@ -258,8 +258,7 @@ const createSupportedSmartWallet = async < type = 'Default', logGas = false, }: CreateSmartWalletParams): Promise => { - const envelopingRequest = createEnvelopingRequest( - true, + const envelopingRequest = createDeployEnvelopingRequest( { relayHub, from: owner.address, @@ -331,8 +330,7 @@ const prepareRelayTransaction = async ({ gas = 0, swAddress, }: PrepareRelayTransactionParams) => { - const envelopingRequest = createEnvelopingRequest( - true, + const envelopingRequest = createDeployEnvelopingRequest( { relayHub, from: owner.address, @@ -484,32 +482,36 @@ const baseRelayRequest: RelayRequestBody = { tokenGas: '0', }; -const createEnvelopingRequest = ( - isDeploy: boolean, +const createRelayEnvelopingRequest = ( request?: Partial | Partial, relayData?: Partial ): EnvelopingRequest => { - return isDeploy - ? { - request: { - ...baseDeployRequest, - ...request, - } as DeployRequestBody, - relayData: { - ...baseRelayData, - ...relayData, - }, - } - : { - request: { - ...baseRelayRequest, - ...request, - } as RelayRequestBody, - relayData: { - ...baseRelayData, - ...relayData, - }, - }; + return { + request: { + ...baseRelayRequest, + ...request, + } as RelayRequestBody, + relayData: { + ...baseRelayData, + ...relayData, + }, + }; +}; + +const createDeployEnvelopingRequest = ( + request?: Partial | Partial, + relayData?: Partial +): EnvelopingRequest => { + return { + request: { + ...baseDeployRequest, + ...request, + } as DeployRequestBody, + relayData: { + ...baseRelayData, + ...relayData, + }, + }; }; const baseUserDefinedDeployBody: UserDefinedDeployRequestBody = { @@ -529,33 +531,38 @@ const baseUserDefinedRelayData: UserDefinedRelayData = { callForwarder: constants.AddressZero, }; -const createUserDefinedRequest = ( - isDeploy: boolean, - request?: Partial, - relayData?: Partial -): UserDefinedRelayRequest | UserDefinedDeployRequest => { - return isDeploy - ? { - request: { - ...baseUserDefinedDeployBody, - ...request, - }, - relayData: { - ...baseUserDefinedRelayData, - ...relayData, - }, - } - : { - request: { - ...baseUserDefinedRelayBody, - ...request, - }, - relayData: { - ...baseUserDefinedRelayData, - ...relayData, - }, - }; +const createRelayUserDefinedRequest = ( + request?: Partial, + relayData?: Partial +): UserDefinedRelayRequest => { + return { + request: { + ...baseUserDefinedRelayBody, + ...request, + }, + relayData: { + ...baseUserDefinedRelayData, + ...relayData, + }, + }; +}; + +const createDeployUserDefinedRequest = ( + request?: Partial, + relayData?: Partial +): UserDefinedDeployRequest => { + return { + request: { + ...baseUserDefinedDeployBody, + ...request, + }, + relayData: { + ...baseUserDefinedRelayData, + ...relayData, + }, + }; }; + type GetSmartWalletAddressParams = { type: SupportedType; factory: SupportedSmartWalletFactory; @@ -596,6 +603,9 @@ async function deployContract(contract: string) { return contractFactory.deploy() as T; } +const getSmartWalletTemplate = (type: SupportedType) => + `${type === 'Default' ? '' : type}SmartWallet`; + export { evmMine, evmMineMany, @@ -607,8 +617,10 @@ export { prepareRelayTransaction, deployRelayHub, deployVerifiers, - createEnvelopingRequest, - createUserDefinedRequest, + createRelayEnvelopingRequest, + createDeployEnvelopingRequest, + createRelayUserDefinedRequest, + createDeployUserDefinedRequest, getSuffixData, signData, generateRandomAddress, @@ -617,6 +629,7 @@ export { RSK_URL, deployContract, getSmartWalletAddress, + getSmartWalletTemplate, }; export type { @@ -628,3 +641,5 @@ export type { SupportedType, SupportedDeployVerifier, }; + +// delete prepareRelayTransaction diff --git a/test/verifier/verifiers.test.ts b/test/verifier/verifiers.test.ts index 17659731..15f40592 100644 --- a/test/verifier/verifiers.test.ts +++ b/test/verifier/verifiers.test.ts @@ -1,5 +1,6 @@ import { BaseProvider } from '@ethersproject/providers'; import { + BoltzSmartWallet, BoltzSmartWalletFactory, DeployVerifier, MinimalBoltzDeployVerifier, @@ -14,7 +15,8 @@ import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'; import { Wallet, providers, constants } from 'ethers'; import { prepareToken } from '../smartwallet/utils'; import { - createEnvelopingRequest, + createDeployEnvelopingRequest, + createRelayEnvelopingRequest, createSupportedSmartWallet, deployContract, RSK_URL, @@ -55,10 +57,9 @@ describe('Verifiers tests', function () { owner = Wallet.createRandom().connect(rskProvider); - const hardHatSmartWalletFactory = await hardhat.getContractFactory( + const smartWalletTemplate = await deployContract( 'SmartWallet' ); - const smartWalletTemplate = await hardHatSmartWalletFactory.deploy(); const hardHatWalletFactory = await hardhat.getContractFactory( 'SmartWalletFactory' @@ -89,8 +90,7 @@ describe('Verifiers tests', function () { }); it('Should succeed when the deploy is correct', async function () { - const deployRequest = createEnvelopingRequest( - true, + const deployRequest = createDeployEnvelopingRequest( { relayHub: relayHub.address, from: owner.address, @@ -120,8 +120,7 @@ describe('Verifiers tests', function () { type: 'Default', }); - const deployRequest = createEnvelopingRequest( - true, + const deployRequest = createDeployEnvelopingRequest( { relayHub: relayHub.address, from: owner.address, @@ -143,8 +142,7 @@ describe('Verifiers tests', function () { }); it('Should fail if the token balance is too low', async function () { - const deployRequest = createEnvelopingRequest( - true, + const deployRequest = createDeployEnvelopingRequest( { relayHub: relayHub.address, from: owner.address, @@ -168,8 +166,7 @@ describe('Verifiers tests', function () { it('Should fail if the token is not allowed', async function () { await deployVerifier.removeToken(testToken.address, 0); - const deployRequest = createEnvelopingRequest( - true, + const deployRequest = createDeployEnvelopingRequest( { relayHub: relayHub.address, from: owner.address, @@ -193,8 +190,7 @@ describe('Verifiers tests', function () { it('Should fail if the factory is incorrect', async function () { const wrongFactory = constants.AddressZero; - const deployRequest = createEnvelopingRequest( - true, + const deployRequest = createDeployEnvelopingRequest( { relayHub: relayHub.address, from: owner.address, @@ -225,10 +221,9 @@ describe('Verifiers tests', function () { let smartWallet: SmartWallet; async function prepareSmartWallet(testToken: TestToken) { - const hardHatSmartWalletFactory = await hardhat.getContractFactory( + const smartWalletTemplate = await deployContract( 'SmartWallet' ); - const smartWalletTemplate = await hardHatSmartWalletFactory.deploy(); const hardHatSmartWalletFactoryFactory = await hardhat.getContractFactory( 'SmartWalletFactory' @@ -272,8 +267,7 @@ describe('Verifiers tests', function () { }); it('Should succeed when the relay is correct', async function () { - const relayRequest = createEnvelopingRequest( - false, + const relayRequest = createRelayEnvelopingRequest( { relayHub: relayHub.address, from: owner.address, @@ -294,8 +288,7 @@ describe('Verifiers tests', function () { }); it('Should fail if the token balance is too low', async function () { - const relayRequest = createEnvelopingRequest( - false, + const relayRequest = createRelayEnvelopingRequest( { relayHub: relayHub.address, from: owner.address, @@ -319,8 +312,7 @@ describe('Verifiers tests', function () { it('Should fail if the token is not allowed', async function () { await relayVerifier.removeToken(testToken.address, 0); - const relayRequest = createEnvelopingRequest( - false, + const relayRequest = createRelayEnvelopingRequest( { relayHub: relayHub.address, from: owner.address, @@ -344,8 +336,7 @@ describe('Verifiers tests', function () { it('Should fail if the factory is incorrect', async function () { const wrongSmartWallet = await prepareSmartWallet(testToken); - const relayRequest = createEnvelopingRequest( - false, + const relayRequest = createRelayEnvelopingRequest( { relayHub: relayHub.address, from: owner.address, @@ -379,10 +370,9 @@ describe('Verifiers tests', function () { owner = Wallet.createRandom().connect(rskProvider); - const hardHatSmartWalletFactory = await hardhat.getContractFactory( + const smartWalletTemplate = await deployContract( 'BoltzSmartWallet' ); - const smartWalletTemplate = await hardHatSmartWalletFactory.deploy(); const hardHatWalletFactory = await hardhat.getContractFactory( 'BoltzSmartWalletFactory' @@ -409,8 +399,7 @@ describe('Verifiers tests', function () { type: 'Default', }); - const deployRequest = createEnvelopingRequest( - true, + const deployRequest = createDeployEnvelopingRequest( { relayHub: relayHub.address, from: owner.address, @@ -431,8 +420,7 @@ describe('Verifiers tests', function () { it('Should fail if the factory is incorrect', async function () { const wrongFactory = constants.AddressZero; - const deployRequest = createEnvelopingRequest( - true, + const deployRequest = createDeployEnvelopingRequest( { relayHub: relayHub.address, from: owner.address, @@ -449,6 +437,7 @@ describe('Verifiers tests', function () { deployVerifier.verifyRelayedCall(deployRequest, signature) ).to.be.rejectedWith('Invalid factory'); }); + describe('Token', function () { let testToken: TestToken; @@ -465,8 +454,7 @@ describe('Verifiers tests', function () { }); it('Should succeed when the deploy is correct', async function () { - const deployRequest = createEnvelopingRequest( - true, + const deployRequest = createDeployEnvelopingRequest( { relayHub: relayHub.address, from: owner.address, @@ -487,8 +475,7 @@ describe('Verifiers tests', function () { }); it('Should fail if the token balance is too low', async function () { - const deployRequest = createEnvelopingRequest( - true, + const deployRequest = createDeployEnvelopingRequest( { relayHub: relayHub.address, from: owner.address, @@ -512,8 +499,7 @@ describe('Verifiers tests', function () { it('Should fail if the token is not allowed', async function () { await deployVerifier.removeToken(testToken.address, 0); - const deployRequest = createEnvelopingRequest( - true, + const deployRequest = createDeployEnvelopingRequest( { relayHub: relayHub.address, from: owner.address, @@ -551,8 +537,7 @@ describe('Verifiers tests', function () { }); it('Should succeed when the deploy is correct', async function () { - const deployRequest = createEnvelopingRequest( - true, + const deployRequest = createDeployEnvelopingRequest( { relayHub: relayHub.address, from: owner.address, @@ -576,8 +561,7 @@ describe('Verifiers tests', function () { it('Should fail if the destination contract is not allowed', async function () { await deployVerifier.removeContract(swap.address, 0); - const deployRequest = createEnvelopingRequest( - true, + const deployRequest = createDeployEnvelopingRequest( { relayHub: relayHub.address, from: owner.address, @@ -600,8 +584,7 @@ describe('Verifiers tests', function () { }); it('Should fail if the token balance is too low', async function () { - const deployRequest = createEnvelopingRequest( - true, + const deployRequest = createDeployEnvelopingRequest( { relayHub: relayHub.address, from: owner.address, @@ -622,8 +605,7 @@ describe('Verifiers tests', function () { }); it('Should fail if the token balance is too low (claim)', async function () { - const deployRequest = createEnvelopingRequest( - true, + const deployRequest = createDeployEnvelopingRequest( { relayHub: relayHub.address, from: owner.address, @@ -669,10 +651,9 @@ describe('Verifiers tests', function () { owner = Wallet.createRandom().connect(rskProvider); - const hardHatSmartWalletFactory = await hardhat.getContractFactory( + const smartWalletTemplate = await deployContract( 'MinimalBoltzSmartWallet' ); - const smartWalletTemplate = await hardHatSmartWalletFactory.deploy(); const hardHatWalletFactory = await hardhat.getContractFactory( 'MinimalBoltzSmartWalletFactory' @@ -701,8 +682,7 @@ describe('Verifiers tests', function () { type: 'Default', }); - const deployRequest = createEnvelopingRequest( - true, + const deployRequest = createDeployEnvelopingRequest( { relayHub: relayHub.address, from: owner.address, @@ -725,8 +705,7 @@ describe('Verifiers tests', function () { it('Should fail if the factory is incorrect', async function () { const wrongFactory = constants.AddressZero; - const deployRequest = createEnvelopingRequest( - true, + const deployRequest = createDeployEnvelopingRequest( { relayHub: relayHub.address, from: owner.address, @@ -749,8 +728,7 @@ describe('Verifiers tests', function () { it('Should fail if payment is with ERC20 token', async function () { const fakeToken = Wallet.createRandom(); - const deployRequest = createEnvelopingRequest( - true, + const deployRequest = createDeployEnvelopingRequest( { relayHub: relayHub.address, from: owner.address, @@ -773,8 +751,7 @@ describe('Verifiers tests', function () { }); it('Should fail if not enough native token for payment', async function () { - const deployRequest = createEnvelopingRequest( - true, + const deployRequest = createDeployEnvelopingRequest( { relayHub: relayHub.address, from: owner.address, @@ -798,8 +775,7 @@ describe('Verifiers tests', function () { it('Should fail if the destination contract is not allowed', async function () { await deployVerifier.removeContract(swap.address, 0); - const deployRequest = createEnvelopingRequest( - true, + const deployRequest = createDeployEnvelopingRequest( { relayHub: relayHub.address, from: owner.address, @@ -820,8 +796,7 @@ describe('Verifiers tests', function () { }); it('Should succeed in sponsored transactions', async function () { - const deployRequest = createEnvelopingRequest( - true, + const deployRequest = createDeployEnvelopingRequest( { relayHub: relayHub.address, from: owner.address, @@ -841,8 +816,7 @@ describe('Verifiers tests', function () { }); it('Should succeed destination contract provide enough balance', async function () { - const deployRequest = createEnvelopingRequest( - true, + const deployRequest = createDeployEnvelopingRequest( { relayHub: relayHub.address, from: owner.address, @@ -876,10 +850,9 @@ describe('Verifiers tests', function () { owner = Wallet.createRandom().connect(rskProvider); - const hardHatSmartWalletFactory = await hardhat.getContractFactory( + const smartWalletTemplate = await deployContract( 'MinimalBoltzSmartWallet' ); - const smartWalletTemplate = await hardHatSmartWalletFactory.deploy(); const hardHatWalletFactory = await hardhat.getContractFactory( 'MinimalBoltzSmartWalletFactory' @@ -907,8 +880,7 @@ describe('Verifiers tests', function () { }); it('Should always fail', async function () { - const relayRequest = createEnvelopingRequest( - false, + const relayRequest = createRelayEnvelopingRequest( { relayHub: relayHub.address, from: owner.address,