From 95f5598334adad37c42c883ad3d6e9dc6894fb0b Mon Sep 17 00:00:00 2001 From: Jacob Caban-Tomski Date: Wed, 26 Oct 2022 21:55:22 -0500 Subject: [PATCH] WIP Further flesh out test --- .../clients/test/OpertionResults.test.ts | 54 +++++++++++++------ 1 file changed, 39 insertions(+), 15 deletions(-) diff --git a/contracts/clients/test/OpertionResults.test.ts b/contracts/clients/test/OpertionResults.test.ts index f3649a4c..2768eb63 100644 --- a/contracts/clients/test/OpertionResults.test.ts +++ b/contracts/clients/test/OpertionResults.test.ts @@ -14,6 +14,16 @@ class MockResult extends Array { } } +const getErrorResult = (actionIndex: number, message: string): string => { + const fullErrorMessage = `${actionIndex} - ${message}`; + const encodedErrorMessage = utils.defaultAbiCoder.encode( + ["string"], + [fullErrorMessage], + ); + // Add empty methodId (4 bytes, 8 chars), remove leading 0 + return `0x${"0".repeat(8)}${encodedErrorMessage.substring(2)}`; +}; + describe("OperationResults", () => { describe("getOperationResults", () => { it("fails if no events are in transaction", () => { @@ -52,7 +62,7 @@ describe("OperationResults", () => { ); }); - it("fails WalletOperationProcessed event is missing args", () => { + it("fails when WalletOperationProcessed event is missing args", () => { const eventMock = TypeMoq.Mock.ofType(); eventMock.setup((e) => e.event).returns(() => "WalletOperationProcessed"); eventMock.setup((e) => e.args).returns(() => undefined); @@ -71,21 +81,15 @@ describe("OperationResults", () => { const errorActionIndex = 0; const errorMessage = "halt and catch fire"; - const fullErrorMessage = `${errorActionIndex} - ${errorMessage}`; - const encodedErrorMessage = utils.defaultAbiCoder.encode( - ["string"], - [fullErrorMessage], - ); - const errorResult = `0x${"0".repeat(8)}${encodedErrorMessage.substring(2)}`; // remove leading 0x - + const errorResult = getErrorResult(errorActionIndex, errorMessage); const failedEventArgs = new MockResult({ wallet: "0x01", nonce: BigNumber.from(0), actions: [ { ethValue: BigNumber.from(0), - contractAddress: "", - encodedFunction: "", + contractAddress: "0xaabbcc", + encodedFunction: "0xddeeff", }, ], success: false, @@ -105,13 +109,13 @@ describe("OperationResults", () => { actions: [ { ethValue: BigNumber.from(0), - contractAddress: "", - encodedFunction: "", + contractAddress: "0xabcabc", + encodedFunction: "0xdefdef", }, { - ethValue: BigNumber.from(0), - contractAddress: "", - encodedFunction: "", + ethValue: BigNumber.from(42), + contractAddress: "0x123123", + encodedFunction: "0x456456", }, ], success: true, @@ -136,6 +140,26 @@ describe("OperationResults", () => { const opResults = getOperationResults(txnReceiptMock.object); expect(opResults).to.have.lengthOf(2); + + const [r1, r2] = opResults; + expect(r1.walletAddress).to.eql(failedEventArgs.wallet); + expect(r1.nonce.toNumber()).to.eql( + BigNumber.from(failedEventArgs.nonce).toNumber(), + ); + expect(r1.actions).to.deep.equal(failedEventArgs.actions); + expect(r1.success).to.eql(failedEventArgs.success); + expect(r1.results).to.deep.equal(failedEventArgs.results); + expect(r1.error?.actionIndex.toNumber()).to.eql(errorActionIndex); + expect(r1.error?.message).to.eql(errorMessage); + + expect(r2.walletAddress).to.eql(successfulEventArgs.wallet); + expect(r2.nonce.toNumber()).to.eql( + BigNumber.from(successfulEventArgs.nonce).toNumber(), + ); + expect(r2.actions).to.deep.equal(successfulEventArgs.actions); + expect(r2.success).to.eql(successfulEventArgs.success); + expect(r2.results).to.deep.equal(successfulEventArgs.results); + expect(r2.error).to.be.undefined; }); }); });