-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path05-stack-depth-128.js
More file actions
57 lines (52 loc) · 1.8 KB
/
05-stack-depth-128.js
File metadata and controls
57 lines (52 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// SIP-039: Increased stack depth from 64 to 128
// Deploys a contract with a chain of 100 functions calling each other.
// Before epoch 3.4, the stack limit of 64 would cause this to fail.
// With the new limit of 128, it should succeed.
const {
makeContractDeploy,
makeContractCall,
ClarityVersion,
PostConditionMode,
getAddressFromPrivateKey,
} = require("@stacks/transactions");
const { STACKS_TESTNET } = require("@stacks/network");
const { PRIVATE_KEY, NETWORK } = require("./config");
const { broadcast } = require("./broadcast");
// Generate a chain of 100 functions: f-0 calls f-1, f-1 calls f-2, ..., f-99 returns ok
const DEPTH = 100;
let code = "";
for (let i = 0; i < DEPTH; i++) {
if (i === DEPTH - 1) {
code += `(define-private (f-${i}) (ok u${i}))\n`;
} else {
code += `(define-private (f-${i}) (f-${i + 1}))\n`;
}
}
code += `(define-public (test-depth) (f-0))\n`;
async function main() {
const deployTx = await makeContractDeploy({
codeBody: code,
contractName: "stack-depth-test",
clarityVersion: ClarityVersion.Clarity5,
senderKey: PRIVATE_KEY,
network: NETWORK,
fee: 200000,
postConditionMode: PostConditionMode.Deny,
});
const deployResult = await broadcast(deployTx, "SIP-039: stack depth contract deploy (100 chained fns)");
if (!deployResult.ok) return;
// Call test-depth
const senderAddress = getAddressFromPrivateKey(PRIVATE_KEY, STACKS_TESTNET);
const callTx = await makeContractCall({
contractAddress: senderAddress,
contractName: "stack-depth-test",
functionName: "test-depth",
functionArgs: [],
senderKey: PRIVATE_KEY,
network: NETWORK,
fee: 500000,
postConditionMode: PostConditionMode.Allow,
});
await broadcast(callTx, "SIP-039: call test-depth (100 deep call chain)");
}
main().catch(console.error);