Skip to content

Commit

Permalink
fix (nearly) all broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonard-Pat committed Jun 7, 2024
1 parent c5bda7e commit 4fc7d61
Showing 1 changed file with 86 additions and 51 deletions.
137 changes: 86 additions & 51 deletions tests-integration/account.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { expect } from "chai";
import { num } from "starknet";
import { Account, RPC, num } from "starknet";
import {
GIFT_MAX_FEE,
buildCallDataClaim,
calculateClaimAddress,
claimInternal,
defaultDepositTestSetup,
Expand Down Expand Up @@ -56,69 +57,103 @@ describe("Gifting", function () {
});
}

// it(`Test only protocol can call claim contract`, async function () {
// const { factory } = await setupGiftProtocol();
// const { claim, claimPrivateKey } = await defaultDepositTestSetup(factory);
// const receiver = randomReceiver();
it(`Test only protocol can call claim contract`, async function () {
const { factory } = await setupGiftProtocol();
const { claim, claimPrivateKey } = await defaultDepositTestSetup(factory);

// await expectRevertWithErrorMessage("gift-acc/only-protocol", () =>
// claimInternal(factory, tokenContract, claimClassHash, claimPrivateKey, receiver),
// );
// });
const claimAddress = calculateClaimAddress(claim);

const claimAccount = new Account(
manager,
num.toHex(claimAddress),
claimPrivateKey,
undefined,
RPC.ETransactionVersion.V2,
);
const claimContract = await manager.loadContract(claimAddress);
claimContract.connect(claimAccount);
await expectRevertWithErrorMessage("gift-acc/only-protocol", () => claimContract.__validate__([]));
});

// it(`Test claim contract cant call another contract`, async function () {
// const { factory } = await setupGiftProtocol();
// it.only(`Test claim contract cant call another contract`, async function () {
// const { factory, claimAccountClassHash } = await setupGiftProtocol();
// const { claim, claimPrivateKey } = await defaultDepositTestSetup(factory);
// const receiver = randomReceiver();

// const claimFakeFactory = { ...claim, factory: "0x123" };
// await expectRevertWithErrorMessage("gift-acc/invalid-call-to", () =>
// claimInternal(claimFakeFactory, claimPrivateKey, receiver),
// const fakeFactory = await manager.deployContract("GiftFactory", {
// unique: true,
// constructorCalldata: [claimAccountClassHash, deployer.address],
// });

// const fakeClaim = { ...claim, factory: fakeFactory.address };
// const claimAddress = calculateClaimAddress(claim);

// const claimAccount = new Account(
// manager,
// num.toHex(claimAddress),
// claimPrivateKey,
// undefined,
// RPC.ETransactionVersion.V2,
// );
// fakeFactory.connect(claimAccount);
// await fakeFactory.claim_internal(buildCallDataClaim(fakeClaim), receiver, { maxFee: 400000000000000n });

// // await expectRevertWithErrorMessage("gift-acc/invalid-call-to", () =>
// // claimInternal(fakeClaim, receiver, claimPrivateKey),
// // );
// });

// it(`Test claim contract can only call 'claim_internal'`, async function () {
// const { factory } = await setupGiftProtocol();
// const { tokenContract, claimAddress, claimClassHash, claimPrivateKey } = await defaultDepositTestSetup(factory);
// const receiver = randomReceiver();
it(`Test claim contract can only call 'claim_internal'`, async function () {
const { factory } = await setupGiftProtocol();
const { claim, claimPrivateKey } = await defaultDepositTestSetup(factory);
const receiver = randomReceiver();

// const claimAccount = new Account(manager, num.toHex(claimAddress), claimPrivateKey, undefined);
const claimAddress = calculateClaimAddress(claim);

// let claim = buildClaim(
// factory,
// claimAccountClassHash,
// GIFT_AMOUNT,
// GIFT_MAX_FEE,
// tokenContract,
// claimSigner.publicKey,
// );
const claimAccount = new Account(
manager,
num.toHex(claimAddress),
claimPrivateKey,
undefined,
RPC.ETransactionVersion.V2,
);

// factory.connect(claimAccount);
// await expectRevertWithErrorMessage("gift-acc/invalid-call-selector", () =>
// factory.get_dust(claim, receiver, { maxFee: 400000000000000n }),
// );
// });
factory.connect(claimAccount);
await expectRevertWithErrorMessage("gift-acc/invalid-call-selector", () =>
factory.get_dust(claim, receiver, { maxFee: 400000000000000n }),
);
});

// it(`Test claim contract cant preform a multicall`, async function () {
// const { factory } = await setupGiftProtocol();
// const { tokenContract, claimSigner } = await defaultDepositTestSetup(factory);
// const receiver = randomReceiver();
it(`Test claim contract cant preform a multicall`, async function () {
const { factory } = await setupGiftProtocol();
const { claim, claimPrivateKey } = await defaultDepositTestSetup(factory);
const receiver = randomReceiver();

// await expectRevertWithErrorMessage("gift-acc/invalid-call-len", () =>
// claimAccount.execute([
// {
// contractAddress: factory.address,
// calldata: [claim, receiver],
// entrypoint: "claim_internal",
// },
// {
// contractAddress: factory.address,
// calldata: [claim, receiver],
// entrypoint: "claim_internal",
// },
// ]),
// );
// });
const claimAddress = calculateClaimAddress(claim);

const claimAccount = new Account(
manager,
num.toHex(claimAddress),
claimPrivateKey,
undefined,
RPC.ETransactionVersion.V2,
);

await expectRevertWithErrorMessage("gift-acc/invalid-call-len", () =>
claimAccount.execute([
{
contractAddress: factory.address,
calldata: [buildCallDataClaim(claim), receiver],
entrypoint: "claim_internal",
},
{
contractAddress: factory.address,
calldata: [buildCallDataClaim(claim), receiver],
entrypoint: "claim_internal",
},
]),
);
});

it(`Test cannot call 'claim_internal' twice`, async function () {
const { factory } = await setupGiftProtocol();
Expand Down

0 comments on commit 4fc7d61

Please sign in to comment.