Skip to content

Commit 125f43e

Browse files
committed
feat: test for indirect calling update-recipient
1 parent 61ee64a commit 125f43e

File tree

5 files changed

+52
-1
lines changed

5 files changed

+52
-1
lines changed

contrib/core-contract-tests/Clarinet.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ clarity_version = 3
4040
epoch = 3.0
4141
depends_on = []
4242

43+
[contracts.sip-031-indirect]
44+
path = "contracts/sip-031-indirect.clar"
45+
clarity_version = 3
46+
epoch = 3.0
47+
depends_on = ["sip-031"]
48+
4349
[contracts.bns_test]
4450
path = "./tests/bns_test.clar"
4551
clarity_version = 2
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
;; This is a wrapper contract to test calling `.sip-031`
2+
;; from an outside contract.
3+
4+
(define-public (update-recipient (new-recipient principal))
5+
(contract-call? 'ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.sip-031 update-recipient new-recipient)
6+
)

contrib/core-contract-tests/deployments/default.simnet-plan.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,9 @@ plan:
9292
emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM
9393
path: "../../stackslib/src/chainstate/stacks/boot/sip-031.clar"
9494
clarity-version: 3
95+
- emulated-contract-publish:
96+
contract-name: sip-031-indirect
97+
emulated-sender: ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM
98+
path: contracts/sip-031-indirect.clar
99+
clarity-version: 3
95100
epoch: "3.0"

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4601,6 +4601,27 @@ export const contracts = {
46014601
clarity_version: "Clarity3",
46024602
contractName: "sip-031",
46034603
},
4604+
sip031Indirect: {
4605+
functions: {
4606+
updateRecipient: {
4607+
name: "update-recipient",
4608+
access: "public",
4609+
args: [{ name: "new-recipient", type: "principal" }],
4610+
outputs: { type: { response: { ok: "bool", error: "int128" } } },
4611+
} as TypedAbiFunction<
4612+
[newRecipient: TypedAbiArg<string, "newRecipient">],
4613+
Response<boolean, bigint>
4614+
>,
4615+
},
4616+
maps: {},
4617+
variables: {},
4618+
constants: {},
4619+
non_fungible_tokens: [],
4620+
fungible_tokens: [],
4621+
epoch: "Epoch30",
4622+
clarity_version: "Clarity3",
4623+
contractName: "sip-031-indirect",
4624+
},
46044625
} as const;
46054626

46064627
export const accounts = {
@@ -4654,6 +4675,7 @@ export const identifiers = {
46544675
signers: "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.signers",
46554676
signersVoting: "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.signers-voting",
46564677
sip031: "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.sip-031",
4678+
sip031Indirect: "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.sip-031-indirect",
46574679
} as const;
46584680

46594681
export const simnet = {
@@ -4705,6 +4727,12 @@ export const deployments = {
47054727
testnet: null,
47064728
mainnet: null,
47074729
},
4730+
sip031Indirect: {
4731+
devnet: "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.sip-031-indirect",
4732+
simnet: "ST1PQHQKV0RJXZFY1DGX8MNSNYVE3VGZJSRTPGZGM.sip-031-indirect",
4733+
testnet: null,
4734+
mainnet: null,
4735+
},
47084736
} as const;
47094737

47104738
export const project = {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { test, expect } from 'vitest';
66
const contracts = projectFactory(project, 'simnet');
77
const contract = contracts.sip031;
88
const constants = contract.constants;
9+
const indirectContract = contracts.sip031Indirect;
910

1011
test('initial recipient should be the deployer', () => {
1112
const value = rov(contract.getRecipient());
@@ -31,4 +32,9 @@ test('updated recipient can re-update the recipient', () => {
3132

3233
txOk(contract.updateRecipient(accounts.wallet_2.address), accounts.wallet_1.address)
3334
expect(rov(contract.getRecipient())).toBe(accounts.wallet_2.address);
34-
});
35+
});
36+
37+
test('recipient cannot be updated from an indirect contract', () => {
38+
const receipt = txErr(indirectContract.updateRecipient(accounts.wallet_1.address), accounts.deployer.address)
39+
expect(receipt.value).toBe(constants.ERR_NOT_ALLOWED);
40+
});

0 commit comments

Comments
 (0)