Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigidity committed Dec 14, 2024
1 parent 0149644 commit 06223e5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 25 deletions.
49 changes: 27 additions & 22 deletions napi/__test__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import {
test("calculate coin id", (t) => {
const coinId = toCoinId({
parentCoinInfo: fromHex(
"4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a"
"4bf5122f344554c53bde2ebb8cd2b7e3d1600ad631c385a5d7cce23c7785459a",
),
puzzleHash: fromHex(
"dbc1b4c900ffe48d575b5da5c638040125f65db0fe3e24494b76ea986457d986"
"dbc1b4c900ffe48d575b5da5c638040125f65db0fe3e24494b76ea986457d986",
),
amount: 100n,
});
Expand All @@ -26,9 +26,9 @@ test("calculate coin id", (t) => {
compareBytes(
coinId,
fromHex(
"fd3e669c27be9d634fe79f1f7d7d8aaacc3597b855cffea1d708f4642f1d542a"
)
)
"fd3e669c27be9d634fe79f1f7d7d8aaacc3597b855cffea1d708f4642f1d542a",
),
),
);
});

Expand Down Expand Up @@ -187,13 +187,13 @@ test("curry roundtrip", (t) => {
const items = Array.from({ length: 10 }, (_, i) => i);
const ptr = clvm.curry(
clvm.nil(),
items.map((i) => clvm.alloc(i))
items.map((i) => clvm.alloc(i)),
);
const uncurry = ptr.uncurry()!;
const args = uncurry.args.map((ptr) => ptr.toSmallNumber());

t.true(
compareBytes(clvm.treeHash(clvm.nil()), clvm.treeHash(uncurry.program))
compareBytes(clvm.treeHash(clvm.nil()), clvm.treeHash(uncurry.program)),
);
t.deepEqual(args, items);
});
Expand Down Expand Up @@ -221,12 +221,12 @@ test("curry tree hash", (t) => {
const items = Array.from({ length: 10 }, (_, i) => i);
const ptr = clvm.curry(
clvm.nil(),
items.map((i) => clvm.alloc(i))
items.map((i) => clvm.alloc(i)),
);

const treeHash = curryTreeHash(
clvm.treeHash(clvm.nil()),
items.map((i) => clvm.treeHash(clvm.alloc(i)))
items.map((i) => clvm.treeHash(clvm.alloc(i))),
);
const expected = clvm.treeHash(ptr);

Expand Down Expand Up @@ -255,7 +255,7 @@ test("mint and spend nft", (t) => {

const spend = clvm.spendP2Standard(
p2.publicKey,
clvm.delegatedSpendForConditions(result.parentConditions)
clvm.delegatedSpendForConditions(result.parentConditions),
);

simulator.spend(
Expand All @@ -266,14 +266,14 @@ test("mint and spend nft", (t) => {
solution: spend.solution.serialize(),
},
]),
[p2.secretKey]
[p2.secretKey],
);

const innerSpend = clvm.spendP2Standard(
p2.publicKey,
clvm.delegatedSpendForConditions([
clvm.createCoin(p2.puzzleHash, 1n, [p2.puzzleHash]),
])
clvm.createCoin(p2.puzzleHash, 1n, clvm.alloc([p2.puzzleHash])),
]),
);

const coinSpends = clvm.spendNft(result.nfts[0], innerSpend);
Expand All @@ -284,11 +284,11 @@ test("mint and spend nft", (t) => {
compareBytes(
clvm
.nftMetadata(
clvm.parseNftMetadata(clvm.deserialize(result.nfts[0].info.metadata))
clvm.parseNftMetadata(clvm.deserialize(result.nfts[0].info.metadata)),
)
.serialize(),
result.nfts[0].info.metadata
)
result.nfts[0].info.metadata,
),
);
});

Expand All @@ -297,12 +297,17 @@ test("create and parse condition", (t) => {

const puzzleHash = fromHex("ff".repeat(32));

const condition = clvm.createCoin(puzzleHash, 1n, [puzzleHash]);
const condition = clvm.createCoin(puzzleHash, 1n, clvm.alloc([puzzleHash]));
const parsed = clvm.parseCreateCoin(condition);

t.deepEqual(parsed, {
puzzleHash,
amount: 1n,
memos: [puzzleHash],
});
t.true(parsed !== null && compareBytes(parsed.puzzleHash, puzzleHash));
t.true(parsed !== null && parsed.amount === 1n);

t.deepEqual(
parsed?.memos
?.toList()
.map((memo) => memo.toAtom())
.filter((memo) => memo !== null),
[puzzleHash],
);
});
4 changes: 2 additions & 2 deletions napi/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export interface AggSigMe {
export interface CreateCoin {
puzzleHash: Uint8Array
amount: bigint
memos: Array<Uint8Array>
memos?: Program
}
export interface ReserveFee {
amount: bigint
Expand Down Expand Up @@ -294,7 +294,7 @@ export declare class ClvmAllocator {
parseAggSigUnsafe(program: Program): AggSigUnsafe | null
aggSigMe(publicKey: PublicKey, message: Uint8Array): Program
parseAggSigMe(program: Program): AggSigMe | null
createCoin(puzzleHash: Uint8Array, amount: bigint, memos: Array<Uint8Array>): Program
createCoin(puzzleHash: Uint8Array, amount: bigint, memos: Program | null): Program
parseCreateCoin(program: Program): CreateCoin | null
reserveFee(amount: bigint): Program
parseReserveFee(program: Program): ReserveFee | null
Expand Down
2 changes: 1 addition & 1 deletion napi/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ impl IntoJsContextual<Option<ClassInstance<Program>>> for Option<Memos<NodePtr>>

let ptr = clvm_allocator
.0
.alloc(&memos)
.alloc(&memos.value)
.map_err(|error| Error::from_reason(format!("Failed to allocate CLVM: {error}")))?;

Ok(Some(Program::new(this, ptr).into_instance(env)?))
Expand Down

0 comments on commit 06223e5

Please sign in to comment.