Skip to content

Instantly share code, notes, and snippets.

@moodmosaic
Created August 10, 2023 21:27
Show Gist options
  • Save moodmosaic/3d79cbd7cbee510a0eb7fcba78b0b21f to your computer and use it in GitHub Desktop.
Save moodmosaic/3d79cbd7cbee510a0eb7fcba78b0b21f to your computer and use it in GitHub Desktop.
A DSL for turning concrete tests into prop/fuzz tests on top of Clarinet.test
Clarinet.test({
name: "ascii-to-buff",
runs: 1000,
logs: true,
data: {
text: {
minLength: 0,
maxLength: 127,
}
},
fn(chain: Chain, account: Account, text: string) {
const expected = Buffer.from(text);
chain.callReadOnlyFn(
"convert7",
"ascii-to-buff",
[types.ascii(text)],
account.address,
).result.expectBuff(expected);
},
});
// Sample output
text: JmGIivX_sePpgoS8c.Oy9fwzJ
chain: Chain { sessionId: 2, blockHeight: 1 }
account: {
address: "ST2NEB84ASENDXKYGJPQW86YXQCEFEX2ZQPG87ND",
balance: 100000000000000,
name: "wallet_4"
}
text: -lt4H(sy\O|AW>Q
chain: Chain { sessionId: 2, blockHeight: 1 }
account: {
address: "ST3PF13W7Z0RRM42A8VZRVFQ75SV1K26RXEP8YGKJ",
balance: 100000000000000,
name: "wallet_7"
}
text: MAPconstructo
./tests-dist/convert_test.js => ascii-to-buff roundtrip ...----- output end -----
./tests-dist/convert_test.js => ascii-to-buff roundtrip ... ok (12s)
ok | 1000 passed | 0 failed (12s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment