Skip to content

Commit

Permalink
fixing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
45930 committed Apr 14, 2024
1 parent 0dbd6f9 commit 3ce669e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 47 deletions.
28 changes: 6 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@
"typescript": "^4.7.2"
},
"peerDependencies": {
"o1js": "^0.16.2"
"o1js": "^0.18.0"
}
}
18 changes: 11 additions & 7 deletions src/lib/packed-types/PackedBool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,17 @@ describe('PackedBool', () => {
packedBool.assertEquals(outsidePackedBool);
});
}).not.toThrow();
expect(() => {
Provable.runAndCheck(() => {
const fakePacked = outsidePackedBool.packed.add(32);
const packedBool = new PackedBool(fakePacked);
packedBool.assertEquals(outsidePackedBool);
});
}).toThrow();

// TODO: This test should not be in the "provable" block since it's not in the runAndCheck
// It seems like failures in the runAndCheck can't be tested for with #toThrow
try {
const fakePacked = outsidePackedBool.packed.add(32);
const packedBool = new PackedBool(fakePacked);
packedBool.assertEquals(outsidePackedBool);
fail('Expected to throw Field.assertEquals error');
} catch (e: any) {
expect(e.message).toContain('Field.assertEquals');
}
});
});
});
20 changes: 11 additions & 9 deletions src/lib/packed-types/PackedString.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,17 @@ describe('PackedString', () => {
});
}).not.toThrow();

expect(() => {
Provable.runAndCheck(() => {
const fakePacked = [...outsideEthAddress.packed];
fakePacked[0] = fakePacked[0].add(1);
const myEthAddress = new EthAddressString(fakePacked);

myEthAddress.assertEquals(outsideEthAddress);
});
}).toThrow();
// TODO: This test should not be in the "provable" block since it's not in the runAndCheck
// It seems like failures in the runAndCheck can't be tested for with #toThrow
try {
const fakePacked = [...outsideEthAddress.packed];
fakePacked[0] = fakePacked[0].add(1);
const myEthAddress = new EthAddressString(fakePacked);
myEthAddress.assertEquals(outsideEthAddress);
fail('Expected to throw Field.assertEquals error');
} catch (e: any) {
expect(e.message).toContain('Field.assertEquals');
}
});
});
});
20 changes: 12 additions & 8 deletions src/lib/packed-types/PackedUInt32.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,24 @@ describe('PackedUInt32', () => {
});
}).not.toThrow();
});
it('#assertEquals', () => {
it('#assertEquals', async () => {
expect(() => {
Provable.runAndCheck(() => {
const packedUInt32 = new PackedUInt32(outsidePackedUInt.packed);
packedUInt32.assertEquals(outsidePackedUInt);
});
}).not.toThrow();
expect(() => {
Provable.runAndCheck(() => {
const fakePacked = outsidePackedUInt.packed.add(32);
const packedUInt32 = new PackedUInt32(fakePacked);
packedUInt32.assertEquals(outsidePackedUInt);
});
}).toThrow();

// TODO: This test should not be in the "provable" block since it's not in the runAndCheck
// It seems like failures in the runAndCheck can't be tested for with #toThrow
try {
const fakePacked = outsidePackedUInt.packed.add(32);
const packedUInt32 = new PackedUInt32(fakePacked);
packedUInt32.assertEquals(outsidePackedUInt);
fail('Expected to throw Field.assertEquals error');
} catch (e: any) {
expect(e.message).toContain('Field.assertEquals');
}
});
});
});

0 comments on commit 3ce669e

Please sign in to comment.