Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

Commit

Permalink
WIP Further flesh out test
Browse files Browse the repository at this point in the history
  • Loading branch information
jacque006 committed Oct 27, 2022
1 parent 657ab87 commit 95f5598
Showing 1 changed file with 39 additions and 15 deletions.
54 changes: 39 additions & 15 deletions contracts/clients/test/OpertionResults.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ class MockResult extends Array<unknown> {
}
}

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", () => {
Expand Down Expand Up @@ -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<Event>();
eventMock.setup((e) => e.event).returns(() => "WalletOperationProcessed");
eventMock.setup((e) => e.args).returns(() => undefined);
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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;
});
});
});

0 comments on commit 95f5598

Please sign in to comment.