Skip to content

Commit 6b12a8d

Browse files
committed
fix: test formatting
1 parent 8b36479 commit 6b12a8d

File tree

1 file changed

+116
-30
lines changed

1 file changed

+116
-30
lines changed

contrib/core-contract-tests/tests/sip-031/sip-031.test.ts

Lines changed: 116 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,29 @@ const indirectContract = contracts.sip031Indirect;
1212
* "Mint" STX to the contract
1313
*/
1414
function mint(amount: number | bigint) {
15-
txOk(indirectContract.transferStx(amount, contract.identifier), accounts.wallet_4.address);
15+
txOk(
16+
indirectContract.transferStx(amount, contract.identifier),
17+
accounts.wallet_4.address,
18+
);
1619
}
1720

1821
// Helper function to mint the initial 200M STX to the contract
1922
function mintInitial() {
2023
// First make sure wallet_4 has enough STX to mint the initial amount
21-
txOk(indirectContract.transferStx(constants.INITIAL_MINT_AMOUNT / 2n, accounts.wallet_4.address), accounts.wallet_5.address);
22-
txOk(indirectContract.transferStx(constants.INITIAL_MINT_AMOUNT / 2n, accounts.wallet_4.address), accounts.wallet_6.address);
24+
txOk(
25+
indirectContract.transferStx(
26+
constants.INITIAL_MINT_AMOUNT / 2n,
27+
accounts.wallet_4.address,
28+
),
29+
accounts.wallet_5.address,
30+
);
31+
txOk(
32+
indirectContract.transferStx(
33+
constants.INITIAL_MINT_AMOUNT / 2n,
34+
accounts.wallet_4.address,
35+
),
36+
accounts.wallet_6.address,
37+
);
2338
// Mint the entire INITIAL_MINT_AMOUNT to the vesting contract
2439
mint(constants.INITIAL_MINT_AMOUNT);
2540
}
@@ -31,36 +46,51 @@ function months(n: number) {
3146
test('initial recipient should be the deployer', () => {
3247
const value = rov(contract.getRecipient());
3348
expect(value).toBe(accounts.deployer.address);
34-
})
49+
});
3550

3651
test('only the recipient can update the recipient', () => {
37-
const receipt = txErr(contract.updateRecipient(accounts.wallet_1.address), accounts.wallet_1.address)
52+
const receipt = txErr(
53+
contract.updateRecipient(accounts.wallet_1.address),
54+
accounts.wallet_1.address,
55+
);
3856

3957
expect(receipt.value).toBe(constants.ERR_NOT_ALLOWED);
4058
});
4159

4260
test('recipient can update the recipient', () => {
43-
txOk(contract.updateRecipient(accounts.wallet_1.address), accounts.deployer.address)
61+
txOk(
62+
contract.updateRecipient(accounts.wallet_1.address),
63+
accounts.deployer.address,
64+
);
4465

4566
const value = rov(contract.getRecipient());
4667
expect(value).toBe(accounts.wallet_1.address);
4768
});
4869

4970
test('updated recipient can re-update the recipient', () => {
50-
txOk(contract.updateRecipient(accounts.wallet_1.address), accounts.deployer.address)
71+
txOk(
72+
contract.updateRecipient(accounts.wallet_1.address),
73+
accounts.deployer.address,
74+
);
5175
expect(rov(contract.getRecipient())).toBe(accounts.wallet_1.address);
5276

53-
txOk(contract.updateRecipient(accounts.wallet_2.address), accounts.wallet_1.address)
77+
txOk(
78+
contract.updateRecipient(accounts.wallet_2.address),
79+
accounts.wallet_1.address,
80+
);
5481
expect(rov(contract.getRecipient())).toBe(accounts.wallet_2.address);
5582
});
5683

5784
test('recipient cannot be updated from an indirect contract', () => {
58-
const receipt = txErr(indirectContract.updateRecipient(accounts.wallet_1.address), accounts.deployer.address)
85+
const receipt = txErr(
86+
indirectContract.updateRecipient(accounts.wallet_1.address),
87+
accounts.deployer.address,
88+
);
5989
expect(receipt.value).toBe(constants.ERR_NOT_ALLOWED);
6090
});
6191

6292
test('errors if claiming as a non-recipient', () => {
63-
const receipt = txErr(contract.claim(), accounts.wallet_1.address)
93+
const receipt = txErr(contract.claim(), accounts.wallet_1.address);
6494
expect(receipt.value).toBe(constants.ERR_NOT_ALLOWED);
6595
});
6696

@@ -69,7 +99,10 @@ test('initial recipient can claim', () => {
6999
const receipt = txOk(contract.claim(), accounts.deployer.address);
70100
expect(receipt.value).toBe(constants.INITIAL_MINT_IMMEDIATE_AMOUNT);
71101

72-
const [event] = filterEvents(receipt.events, CoreNodeEventType.StxTransferEvent);
102+
const [event] = filterEvents(
103+
receipt.events,
104+
CoreNodeEventType.StxTransferEvent,
105+
);
73106
expect(event.data.amount).toBe(`${constants.INITIAL_MINT_IMMEDIATE_AMOUNT}`);
74107
expect(event.data.recipient).toBe(accounts.deployer.address);
75108
expect(event.data.sender).toBe(contract.identifier);
@@ -81,12 +114,18 @@ test('updated recipient can claim', () => {
81114
const balance = rov(indirectContract.getBalance(contract.identifier));
82115
expect(balance).toBe(constants.INITIAL_MINT_AMOUNT);
83116

84-
txOk(contract.updateRecipient(accounts.wallet_1.address), accounts.deployer.address);
117+
txOk(
118+
contract.updateRecipient(accounts.wallet_1.address),
119+
accounts.deployer.address,
120+
);
85121
const receipt = txOk(contract.claim(), accounts.wallet_1.address);
86122
expect(receipt.value).toBe(constants.INITIAL_MINT_IMMEDIATE_AMOUNT);
87123

88124
expect(receipt.events.length).toBe(2);
89-
const stxTransferEvents = filterEvents(receipt.events, CoreNodeEventType.StxTransferEvent);
125+
const stxTransferEvents = filterEvents(
126+
receipt.events,
127+
CoreNodeEventType.StxTransferEvent,
128+
);
90129
expect(stxTransferEvents.length).toBe(1);
91130
const [event] = stxTransferEvents;
92131
expect(event.data.amount).toBe(`${constants.INITIAL_MINT_IMMEDIATE_AMOUNT}`);
@@ -109,19 +148,27 @@ test('calculating vested amounts at a block height', () => {
109148
return immediateAmount + vestingAmount;
110149
}
111150

112-
expect(rov(contract.calcClaimableAmount(deployBlockHeight))).toBe(immediateAmount);
151+
expect(rov(contract.calcClaimableAmount(deployBlockHeight))).toBe(
152+
immediateAmount,
153+
);
113154

114155
function expectAmount(month: bigint) {
115156
const burnHeight = deployBlockHeight + month * 4383n;
116-
expect(rov(contract.calcClaimableAmount(burnHeight))).toBe(expectedAmount(burnHeight));
157+
expect(rov(contract.calcClaimableAmount(burnHeight))).toBe(
158+
expectedAmount(burnHeight),
159+
);
117160
}
118161

119162
for (let i = 1n; i < 24n; i++) {
120163
expectAmount(i);
121164
}
122165
// At 24+ months, the entire vesting bucket should be unlocked
123-
expect(rov(contract.calcClaimableAmount(deployBlockHeight + 24n * 4383n))).toBe(initialMintAmount);
124-
expect(rov(contract.calcClaimableAmount(deployBlockHeight + 25n * 4383n))).toBe(initialMintAmount);
166+
expect(
167+
rov(contract.calcClaimableAmount(deployBlockHeight + 24n * 4383n)),
168+
).toBe(initialMintAmount);
169+
expect(
170+
rov(contract.calcClaimableAmount(deployBlockHeight + 25n * 4383n)),
171+
).toBe(initialMintAmount);
125172
});
126173

127174
// -----------------------------------------------------------------------------
@@ -135,10 +182,16 @@ test('claim scenario 1', () => {
135182
mint(100n * 1000000n);
136183
simnet.mineEmptyBlocks(months(1));
137184
const receipt = txOk(contract.claim(), accounts.deployer.address);
138-
const expected = constants.INITIAL_MINT_IMMEDIATE_AMOUNT + constants.INITIAL_MINT_VESTING_AMOUNT / 24n + 100n * 1000000n;
185+
const expected =
186+
constants.INITIAL_MINT_IMMEDIATE_AMOUNT +
187+
constants.INITIAL_MINT_VESTING_AMOUNT / 24n +
188+
100n * 1000000n;
139189
expect(receipt.value).toBe(expected);
140190

141-
const [event] = filterEvents(receipt.events, CoreNodeEventType.StxTransferEvent);
191+
const [event] = filterEvents(
192+
receipt.events,
193+
CoreNodeEventType.StxTransferEvent,
194+
);
142195
expect(event.data.amount).toBe(expected.toString());
143196
expect(event.data.recipient).toBe(accounts.deployer.address);
144197
expect(event.data.sender).toBe(contract.identifier);
@@ -147,24 +200,31 @@ test('claim scenario 1', () => {
147200
mint(500n * 1000000n);
148201
simnet.mineEmptyBlocks(months(4));
149202
const receipt2 = txOk(contract.claim(), accounts.deployer.address);
150-
const expected2 = constants.INITIAL_MINT_VESTING_AMOUNT / 24n * 4n + 500n * 1000000n;
203+
const expected2 =
204+
(constants.INITIAL_MINT_VESTING_AMOUNT / 24n) * 4n + 500n * 1000000n;
151205
expect(receipt2.value).toBe(expected2);
152206

153-
const [event2] = filterEvents(receipt2.events, CoreNodeEventType.StxTransferEvent);
207+
const [event2] = filterEvents(
208+
receipt2.events,
209+
CoreNodeEventType.StxTransferEvent,
210+
);
154211
expect(event2.data.amount).toBe(expected2.toString());
155212
expect(event2.data.recipient).toBe(accounts.deployer.address);
156213

157214
// wait until end of vesting (20 more months), with an extra 1500 STX
158215
// calc remainder of unvested, to deal with integer division
159-
const vestedAlready = constants.INITIAL_MINT_VESTING_AMOUNT / 24n * 5n;
216+
const vestedAlready = (constants.INITIAL_MINT_VESTING_AMOUNT / 24n) * 5n;
160217
const unvested = constants.INITIAL_MINT_VESTING_AMOUNT - vestedAlready;
161218
const expected3 = unvested + 1500n * 1000000n;
162219
mint(1500n * 1000000n);
163220
simnet.mineEmptyBlocks(months(20));
164221
const receipt3 = txOk(contract.claim(), accounts.deployer.address);
165222
expect(receipt3.value).toBe(expected3);
166223

167-
const [event3] = filterEvents(receipt3.events, CoreNodeEventType.StxTransferEvent);
224+
const [event3] = filterEvents(
225+
receipt3.events,
226+
CoreNodeEventType.StxTransferEvent,
227+
);
168228
expect(event3.data.amount).toBe(expected3.toString());
169229
expect(event3.data.recipient).toBe(accounts.deployer.address);
170230

@@ -176,11 +236,14 @@ test('claim scenario 1', () => {
176236
const receipt4 = txOk(contract.claim(), accounts.deployer.address);
177237
expect(receipt4.value).toBe(expected4);
178238

179-
const [event4] = filterEvents(receipt4.events, CoreNodeEventType.StxTransferEvent);
239+
const [event4] = filterEvents(
240+
receipt4.events,
241+
CoreNodeEventType.StxTransferEvent,
242+
);
180243
expect(event4.data.amount).toBe(expected4.toString());
181244
expect(event4.data.recipient).toBe(accounts.deployer.address);
182245
expect(rov(indirectContract.getBalance(contract.identifier))).toBe(0n);
183-
})
246+
});
184247

185248
// -----------------------------------------------------------------------------
186249
// Edge-case: Claim when the contract holds *zero* balance should revert
@@ -233,7 +296,9 @@ test('final vesting iteration flushes rounding remainder', () => {
233296
simnet.mineEmptyBlocks(months(23));
234297

235298
// First claim: immediate bucket + 23/24 of vesting bucket
236-
const perIteration = constants.INITIAL_MINT_VESTING_AMOUNT / constants.INITIAL_MINT_VESTING_ITERATIONS;
299+
const perIteration =
300+
constants.INITIAL_MINT_VESTING_AMOUNT /
301+
constants.INITIAL_MINT_VESTING_ITERATIONS;
237302
const expectedFirst =
238303
constants.INITIAL_MINT_IMMEDIATE_AMOUNT + perIteration * 23n;
239304
const first = txOk(contract.claim(), accounts.deployer.address);
@@ -266,20 +331,28 @@ test('new recipient claims vested tranche plus extra deposit', () => {
266331
simnet.mineEmptyBlocks(months(1));
267332

268333
// Update recipient to wallet_1
269-
txOk(contract.updateRecipient(accounts.wallet_1.address), accounts.deployer.address);
334+
txOk(
335+
contract.updateRecipient(accounts.wallet_1.address),
336+
accounts.deployer.address,
337+
);
270338

271339
// External party deposits 500 STX
272340
const extraDeposit = 500n * 1000000n;
273341
mint(extraDeposit);
274342

275343
// Wallet_1 claims: should receive 1/24 of vesting bucket + 500 STX
276-
const perIteration = constants.INITIAL_MINT_VESTING_AMOUNT / constants.INITIAL_MINT_VESTING_ITERATIONS;
344+
const perIteration =
345+
constants.INITIAL_MINT_VESTING_AMOUNT /
346+
constants.INITIAL_MINT_VESTING_ITERATIONS;
277347
const expected = perIteration + extraDeposit;
278348
const receipt = txOk(contract.claim(), accounts.wallet_1.address);
279349
expect(receipt.value).toBe(expected);
280350

281351
// Validate transfer event
282-
const [evt] = filterEvents(receipt.events, CoreNodeEventType.StxTransferEvent);
352+
const [evt] = filterEvents(
353+
receipt.events,
354+
CoreNodeEventType.StxTransferEvent,
355+
);
283356
expect(evt.data.amount).toBe(expected.toString());
284357
expect(evt.data.recipient).toBe(accounts.wallet_1.address);
285358
expect(evt.data.sender).toBe(contract.identifier);
@@ -292,7 +365,10 @@ test('calculating claimable amount at invalid block height returns 0', () => {
292365
});
293366

294367
test('print events are emitted when updating recipient', () => {
295-
const receipt = txOk(contract.updateRecipient(accounts.wallet_1.address), accounts.deployer.address);
368+
const receipt = txOk(
369+
contract.updateRecipient(accounts.wallet_1.address),
370+
accounts.deployer.address,
371+
);
296372
expect(receipt.events.length).toBe(1);
297373
const [event] = filterEvents(receipt.events, CoreNodeEventType.ContractEvent);
298374
const printData = cvToValue<{
@@ -318,3 +394,13 @@ test('print events are emitted when claiming', () => {
318394
expect(printData.claimable).toBe(constants.INITIAL_MINT_IMMEDIATE_AMOUNT);
319395
expect(printData.recipient).toBe(accounts.deployer.address);
320396
});
397+
398+
test('claiming after waiting more than 1 month', () => {
399+
mintInitial();
400+
simnet.mineEmptyBlocks(months(1));
401+
const receipt = txOk(contract.claim(), accounts.deployer.address);
402+
expect(receipt.value).toBe(
403+
constants.INITIAL_MINT_IMMEDIATE_AMOUNT +
404+
constants.INITIAL_MINT_VESTING_AMOUNT / 24n,
405+
);
406+
});

0 commit comments

Comments
 (0)