Skip to content

Commit a1bb7eb

Browse files
committed
test: setting a contract as the SIP-031 recipient
1 parent a79f9e1 commit a1bb7eb

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

contrib/core-contract-tests/contracts/sip-031-indirect.clar

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,22 @@
77
)
88
)
99

10+
;; WARNING: This is for testing purposes only.
11+
;; This is not a safe way to call `update-recipient` from an external contract,
12+
;; as it does not perform the necessary authorization checks.
13+
(define-public (update-recipient-as-contract (new-recipient principal))
14+
(as-contract (contract-call? 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.sip-031
15+
update-recipient new-recipient
16+
))
17+
)
18+
19+
;; WARNING: This is for testing purposes only.
20+
;; This is not a safe way to call `claim` from an external contract,
21+
;; as it does not perform the necessary authorization checks.
22+
(define-public (claim-as-contract)
23+
(as-contract (contract-call? 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.sip-031 claim))
24+
)
25+
1026
;; Helper function to transfer STX within tests
1127
(define-public (transfer-stx
1228
(amount uint)

contrib/core-contract-tests/tests/clarigen-types.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4687,6 +4687,12 @@ export const contracts = {
46874687
},
46884688
sip031Indirect: {
46894689
functions: {
4690+
claimAsContract: {
4691+
name: 'claim-as-contract',
4692+
access: 'public',
4693+
args: [],
4694+
outputs: { type: { response: { ok: 'uint128', error: 'uint128' } } },
4695+
} as TypedAbiFunction<[], Response<bigint, bigint>>,
46904696
transferStx: {
46914697
name: 'transfer-stx',
46924698
access: 'public',
@@ -4711,6 +4717,15 @@ export const contracts = {
47114717
[newRecipient: TypedAbiArg<string, 'newRecipient'>],
47124718
Response<boolean, bigint>
47134719
>,
4720+
updateRecipientAsContract: {
4721+
name: 'update-recipient-as-contract',
4722+
access: 'public',
4723+
args: [{ name: 'new-recipient', type: 'principal' }],
4724+
outputs: { type: { response: { ok: 'bool', error: 'uint128' } } },
4725+
} as TypedAbiFunction<
4726+
[newRecipient: TypedAbiArg<string, 'newRecipient'>],
4727+
Response<boolean, bigint>
4728+
>,
47144729
getBalance: {
47154730
name: 'get-balance',
47164731
access: 'read_only',

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,31 @@ test('recipient change during vesting period preserves vested amounts', () => {
671671
expect(secondClaim.value).toBe(expectedVested);
672672
});
673673

674+
test('recipient can be updated from an indirect contract set as recipient', () => {
675+
txOk(
676+
contract.updateRecipient(indirectContract.identifier),
677+
accounts.deployer.address,
678+
);
679+
txOk(
680+
indirectContract.updateRecipientAsContract(accounts.wallet_1.address),
681+
accounts.wallet_1.address,
682+
);
683+
expect(rov(contract.getRecipient())).toBe(accounts.wallet_1.address);
684+
});
685+
686+
test('claim can be called from an indirect contract set as recipient', () => {
687+
mintInitial();
688+
txOk(
689+
contract.updateRecipient(indirectContract.identifier),
690+
accounts.deployer.address,
691+
);
692+
let receipt = txOk(
693+
indirectContract.claimAsContract(),
694+
accounts.wallet_1.address,
695+
);
696+
expect(receipt.value).toBe(constants.INITIAL_MINT_IMMEDIATE_AMOUNT);
697+
});
698+
674699
// -----------------------------------------------------------------------------
675700
// Fuzz Testing - Randomized Tests
676701
// -----------------------------------------------------------------------------

0 commit comments

Comments
 (0)