-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e04942d
commit d313bd9
Showing
4 changed files
with
74 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,20 @@ | ||
import { uint256 } from "starknet"; | ||
import { LegacyStarknetKeyPair, deployer, getClaimExternalData, manager } from "../lib"; | ||
import { deployer, getClaimExternalData, manager } from "../lib"; | ||
import { GIFT_SIGNER, setupClaim } from "./setupClaim"; | ||
|
||
describe("claim_external", function () { | ||
const useTxV3 = true; | ||
it(`Testing claim_external flow using txV3: ${useTxV3}`, async function () { | ||
await manager.restartDevnetAndClearClassCache(); | ||
// Deploy factory | ||
const claimAccountClassHash = await manager.declareLocalContract("ClaimAccount"); | ||
const factory = await manager.deployContract("GiftFactory", { | ||
unique: true, | ||
constructorCalldata: [claimAccountClassHash, deployer.address], | ||
}); | ||
const signer = new LegacyStarknetKeyPair(); | ||
const claimPubkey = signer.publicKey; | ||
const amount = 1000000000000000n; | ||
const maxFee = 50000000000000n; | ||
const receiver = "0x42"; | ||
|
||
// Make a gift | ||
const tokenContract = await manager.tokens.feeTokenContract(useTxV3); | ||
tokenContract.connect(deployer); | ||
factory.connect(deployer); | ||
await tokenContract.approve(factory.address, amount + maxFee); | ||
await factory.deposit(amount, maxFee, tokenContract.address, claimPubkey); | ||
|
||
const claimAddress = await factory.get_claim_address( | ||
deployer.address, | ||
amount, | ||
maxFee, | ||
tokenContract.address, | ||
claimPubkey, | ||
); | ||
before(async () => { | ||
await manager.declareLocalContract("ClaimAccount"); | ||
}); | ||
|
||
const claim = { | ||
factory: factory.address, | ||
class_hash: claimAccountClassHash, | ||
sender: deployer.address, | ||
amount: uint256.bnToUint256(amount), | ||
max_fee: maxFee, | ||
token: tokenContract.address, | ||
claim_pubkey: claimPubkey, | ||
}; | ||
for (const useTxV3 of [false, true]) { | ||
it(`Testing claim_external flow using txV3: ${useTxV3}`, async function () { | ||
const { factory, claimAccount, claim, receiver } = await setupClaim(useTxV3); | ||
|
||
const claimExternalData = await getClaimExternalData({ receiver }); | ||
const signature = await signer.signMessage(claimExternalData, claimAddress); | ||
const claimExternalData = await getClaimExternalData({ receiver }); | ||
const signature = await GIFT_SIGNER.signMessage(claimExternalData, claimAccount.address); | ||
|
||
await factory.claim_external(claim, receiver, signature); | ||
}); | ||
factory.connect(deployer); | ||
await factory.claim_external(claim, receiver, signature); | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.