-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03-from-consensus-buff-empty.js
More file actions
59 lines (52 loc) · 1.85 KB
/
03-from-consensus-buff-empty.js
File metadata and controls
59 lines (52 loc) · 1.85 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
58
59
// SIP-039: from-consensus-buff? with empty buffer no longer errors (issue #6683)
// Deploys a contract that calls from-consensus-buff? with an empty buffer.
// Before epoch 3.4 this would trigger a runtime cost error.
// Now it should return none.
const {
makeContractDeploy,
ClarityVersion,
PostConditionMode,
getAddressFromPrivateKey,
} = require("@stacks/transactions");
const { STACKS_TESTNET } = require("@stacks/network");
const { PRIVATE_KEY, NETWORK, API_URL } = require("./config");
const { broadcast } = require("./broadcast");
const codeBody = `
;; This should return none instead of erroring
(define-read-only (test-empty-buff)
(from-consensus-buff? uint 0x)
)
;; Sanity check: valid consensus buffer for a uint
(define-read-only (test-valid-buff)
(from-consensus-buff? uint 0x0000000000000000000000000000002a)
)
`;
async function main() {
const tx = await makeContractDeploy({
codeBody,
contractName: "consensus-buff-empty-test",
clarityVersion: ClarityVersion.Clarity5,
senderKey: PRIVATE_KEY,
network: NETWORK,
fee: 50000,
postConditionMode: PostConditionMode.Deny,
});
const result = await broadcast(tx, "SIP-039: from-consensus-buff? with empty buffer");
if (!result.ok) return;
// Call the read-only functions to verify behavior
const senderAddress = getAddressFromPrivateKey(PRIVATE_KEY, STACKS_TESTNET);
const contractId = `${senderAddress}.consensus-buff-empty-test`;
for (const fn of ["test-empty-buff", "test-valid-buff"]) {
const res = await fetch(
`${API_URL}/v2/contracts/call-read/${contractId}/${fn}`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ sender: senderAddress, arguments: [] }),
}
);
const data = await res.json();
console.log(`\n ${fn}: ${data.result}`);
}
}
main().catch(console.error);