Skip to content

Commit

Permalink
fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gaetbout committed Jun 6, 2024
1 parent 573332c commit af31b52
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
1 change: 1 addition & 0 deletions scripts/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ for (const useTxV3 of [false, true]) {

// Ensure there is a contract for the claim
const claimAddress = await factory.get_claim_address(
claimAccountClassHash,
deployer.address,
amount,
maxFee,
Expand Down
25 changes: 18 additions & 7 deletions tests-integration/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe("Gifting", function () {

// Ensure there is a contract for the claim
const claimAddress = await factory.get_claim_address(
claimAccountClassHash,
deployer.address,
amount,
maxFee,
Expand Down Expand Up @@ -74,7 +75,7 @@ describe("Gifting", function () {
max_price_per_unit: num.toHexString(4),
},
};
await expectRevertWithErrorMessage("gift-acc/insufficient-v3-fee", () =>
await expectRevertWithErrorMessage("gift-acc/max-fee-too-high-v3", () =>
claimAccount.execute(
[
{
Expand All @@ -88,7 +89,7 @@ describe("Gifting", function () {
),
);
} else {
await expectRevertWithErrorMessage("gift-acc/insufficient-v1-fee", () =>
await expectRevertWithErrorMessage("gift-acc/max-fee-too-high-v1", () =>
factory.claim_internal(claim, receiver, { maxFee: maxFee + 1n }),
);
}
Expand Down Expand Up @@ -124,25 +125,29 @@ describe("Gifting", function () {

// Ensure there is a contract for the claim
const claimAddress = await factory.get_claim_address(
claimAccountClassHash,
deployer.address,
amount,
maxFee,
tokenContract.address,
claimPubkey,
);

const claim = {
factory: factory.address,
class_hash: claimAccountClassHash,
const constructorArgs = {
sender: deployer.address,
amount: uint256.bnToUint256(amount),
max_fee: maxFee,
token: tokenContract.address,
claim_pubkey: claimPubkey,
};

const constructorCalldata = CallData.compile(claim);
const correctAddress = hash.calculateContractAddressFromHash(0, claimAccountClassHash, constructorCalldata, 0);
const constructorCalldata = CallData.compile(constructorArgs);
const correctAddress = hash.calculateContractAddressFromHash(
0,
claimAccountClassHash,
constructorCalldata,
factory.address,
);
expect(claimAddress).to.be.equal(num.toBigInt(correctAddress));

// Check balance of the claim contract is correct
Expand All @@ -156,6 +161,12 @@ describe("Gifting", function () {
claimContract.connect(claimAccount);
await expectRevertWithErrorMessage("gift-acc/only-protocol", () => claimContract.__validate__([]));

const claim = {
factory: factory.address,
class_hash: claimAccountClassHash,
...constructorArgs
};

// cant call another contract
fakeFactory.connect(claimAccount);
await expectRevertWithErrorMessage("gift-acc/invalid-call-to", () =>
Expand Down
1 change: 1 addition & 0 deletions tests-integration/claim_external.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ describe("claim_external", function () {
await factory.deposit(amount, maxFee, tokenContract.address, claimPubkey);

const claimAddress = await factory.get_claim_address(
claimAccountClassHash,
deployer.address,
amount,
maxFee,
Expand Down
5 changes: 4 additions & 1 deletion tests-integration/factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ describe("Factory", function () {

// Ensure there is a contract for the claim
const claimAddress = await factory.get_claim_address(
claimAccountClassHash,
deployer.address,
amount,
maxFee,
Expand Down Expand Up @@ -94,6 +95,7 @@ describe("Factory", function () {

// Ensure there is a contract for the claim
const claimAddress = await factory.get_claim_address(
claimAccountClassHash,
deployer.address,
amount,
maxFee,
Expand Down Expand Up @@ -130,7 +132,7 @@ describe("Factory", function () {
await tokenContract.balance_of(claimAddress).should.eventually.equal(0n);

factory.connect(claimAccount);
await expectRevertWithErrorMessage("gift-acc/gift-canceled", () => factory.claim_internal(claim, receiver));
await expectRevertWithErrorMessage("gift/already-claimed-or-cancel", () => factory.claim_internal(claim, receiver));
});

it(`Test pausable`, async function () {
Expand Down Expand Up @@ -166,6 +168,7 @@ describe("Factory", function () {

// Ensure there is a contract for the claim
const claimAddress = await factory.get_claim_address(
claimAccountClassHash,
deployer.address,
amount,
maxFee,
Expand Down

0 comments on commit af31b52

Please sign in to comment.