From a7c54cced9634209b7381f0c992482323c6f3f1a Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 14 Jun 2023 14:27:35 +0200 Subject: [PATCH 01/17] docs(template): change test description --- tests/template.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/template.test.ts b/tests/template.test.ts index 8912ee6..73bc983 100644 --- a/tests/template.test.ts +++ b/tests/template.test.ts @@ -48,7 +48,7 @@ describe("a template", async () => { }) - it ("docs the tx ingridients", async ({network, alice, validatorHash}) => { + it ("documents the initial state of the Emulator", async ({network, alice, validatorHash}) => { // https://www.hyperion-bt.org/helios-book/api/reference/address.html?highlight=Address#address const aliceUtxos = await network.getUtxos(alice.address); // todo From 175c3c1f060579822fc524d819975dc844e3f93b Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 14 Jun 2023 14:30:39 +0200 Subject: [PATCH 02/17] docs(t/cv): refactor --- tests/vesting-cancel.test.ts | 54 ++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/tests/vesting-cancel.test.ts b/tests/vesting-cancel.test.ts index 3217729..0338718 100644 --- a/tests/vesting-cancel.test.ts +++ b/tests/vesting-cancel.test.ts @@ -51,7 +51,7 @@ describe("a vesting contract: Cancel transaction", async () => { context.network = network; }) - it ("docs the tx ingridients", async ({network, alice, validatorHash}) => { + it ("documents properties", async ({network, alice, validatorHash}) => { // network.getUtxos(alice.address) // EmulatorWallet const aliceUtxos = await alice.utxos; @@ -64,7 +64,32 @@ describe("a vesting contract: Cancel transaction", async () => { }) - it ("locks funds and tries to unlock as the owner", async ({network, alice, bob, program}) => { + it ("tests cancelVesting.ts", async ({network, alice, bob, program}) => { + const optimize = false; // need to add it to the context + const compiledScript = program.compile(optimize); + const validatorHash = compiledScript.validatorHash; + const validatorAddress = Address.fromValidatorHash(validatorHash); + + expect((await alice.utxos)[0].value.dump().lovelace).toBe('20000000'); + expect((await alice.utxos)[1].value.dump().lovelace).toBe('50000000'); + + const adaQty = 10; + const duration = 1000000; + await lockAda(network!, alice!, bob!, program, adaQty, duration); + expect((await alice.utxos)[0].value.dump().lovelace).toBe('50000000'); + expect((await alice.utxos)[1].value.dump().lovelace).toBe('9755287'); + + await cancelVesting(network!, alice!, program ); + + const oracle = await alice.utxos; + + // think about which is which. + expect(oracle[2].value.dump().lovelace).toBe('9546007'); + expect(oracle[1].value.dump().lovelace).toBe('10000000');// + expect(oracle[0].value.dump().lovelace).toBe('50000000');// collateral? + }) + + it ("describes the transaction", async ({network, alice, bob, program}) => { // Obtain UPLC: // need to add it to the context // Compile the Helios script @@ -83,7 +108,6 @@ describe("a vesting contract: Cancel transaction", async () => { expect((await alice.utxos)[0].value.dump().lovelace).toBe('50000000'); expect((await alice.utxos)[1].value.dump().lovelace).toBe('9755287'); - const networkParamsFile = await fs.readFile('./src/preprod.json', 'utf8'); const networkParams = new NetworkParams(JSON.parse(networkParamsFile.toString())); @@ -131,30 +155,6 @@ describe("a vesting contract: Cancel transaction", async () => { const oracle = await alice.utxos; - // think about which is which. - expect(oracle[2].value.dump().lovelace).toBe('9546007'); - expect(oracle[1].value.dump().lovelace).toBe('10000000');// - expect(oracle[0].value.dump().lovelace).toBe('50000000');// collateral? - }) - it ("tests cancelVesting.ts", async ({network, alice, bob, program}) => { - const optimize = false; // need to add it to the context - const compiledScript = program.compile(optimize); - const validatorHash = compiledScript.validatorHash; - const validatorAddress = Address.fromValidatorHash(validatorHash); - - expect((await alice.utxos)[0].value.dump().lovelace).toBe('20000000'); - expect((await alice.utxos)[1].value.dump().lovelace).toBe('50000000'); - - const adaQty = 10; - const duration = 1000000; - await lockAda(network!, alice!, bob!, program, adaQty, duration); - expect((await alice.utxos)[0].value.dump().lovelace).toBe('50000000'); - expect((await alice.utxos)[1].value.dump().lovelace).toBe('9755287'); - - await cancelVesting(network!, alice!, program ); - - const oracle = await alice.utxos; - // think about which is which. expect(oracle[2].value.dump().lovelace).toBe('9546007'); expect(oracle[1].value.dump().lovelace).toBe('10000000');// From 4eb846ab549d6b8101141278c9185f82ba46bdbe Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 14 Jun 2023 14:39:57 +0200 Subject: [PATCH 03/17] refactor(t/vc): sort things --- tests/vesting-cancel.test.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/vesting-cancel.test.ts b/tests/vesting-cancel.test.ts index 0338718..f40c5d7 100644 --- a/tests/vesting-cancel.test.ts +++ b/tests/vesting-cancel.test.ts @@ -52,16 +52,16 @@ describe("a vesting contract: Cancel transaction", async () => { }) it ("documents properties", async ({network, alice, validatorHash}) => { - // network.getUtxos(alice.address) - // EmulatorWallet - const aliceUtxos = await alice.utxos; // https://www.hyperion-bt.org/helios-book/api/reference/address.html?highlight=Address#address expect(alice.address.toHex().length).toBe(58) - // UTxO - expect(aliceUtxos[1].value.dump().lovelace).toBe('50000000') + // UTxOs + expect((await alice.utxos)[0].value.dump().lovelace).toBe('20000000'); + expect((await alice.utxos)[1].value.dump().lovelace).toBe('50000000'); + // https://www.hyperion-bt.org/helios-book/lang/builtins/validatorhash.html?highlight=valida#validatorhash expect(validatorHash.hex).toBe('e7015c6a1424d748f8241fe3a43b3a382b35dc9ca67320e3ee863dc8') + }) it ("tests cancelVesting.ts", async ({network, alice, bob, program}) => { @@ -70,8 +70,6 @@ describe("a vesting contract: Cancel transaction", async () => { const validatorHash = compiledScript.validatorHash; const validatorAddress = Address.fromValidatorHash(validatorHash); - expect((await alice.utxos)[0].value.dump().lovelace).toBe('20000000'); - expect((await alice.utxos)[1].value.dump().lovelace).toBe('50000000'); const adaQty = 10; const duration = 1000000; From b4e6024db9b184aad6ed562422f0ca214287380f Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 14 Jun 2023 14:42:06 +0200 Subject: [PATCH 04/17] style(t/cv): rm line --- tests/vesting-cancel.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/vesting-cancel.test.ts b/tests/vesting-cancel.test.ts index f40c5d7..c231320 100644 --- a/tests/vesting-cancel.test.ts +++ b/tests/vesting-cancel.test.ts @@ -70,7 +70,6 @@ describe("a vesting contract: Cancel transaction", async () => { const validatorHash = compiledScript.validatorHash; const validatorAddress = Address.fromValidatorHash(validatorHash); - const adaQty = 10; const duration = 1000000; await lockAda(network!, alice!, bob!, program, adaQty, duration); From 20733645fbd4a7c22d61e9963690fd763f6970af Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 14 Jun 2023 14:50:41 +0200 Subject: [PATCH 05/17] test(t/tp): add a check for validity interval --- tests/time-props-vesting.test.ts | 116 +++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 tests/time-props-vesting.test.ts diff --git a/tests/time-props-vesting.test.ts b/tests/time-props-vesting.test.ts new file mode 100644 index 0000000..932ded4 --- /dev/null +++ b/tests/time-props-vesting.test.ts @@ -0,0 +1,116 @@ +import { describe, expect, it, expectTypeOf, beforeEach, vi } from 'vitest' +import { promises as fs } from 'fs'; +import { + Address, + Assets, + ByteArrayData, + ConstrData, + Datum, + hexToBytes, + IntData, + ListData, + NetworkEmulator, + NetworkParams, + Program, + Tx, + TxOutput, + Value, +} from "@hyperionbt/helios"; +import {lockAda} from './src/vesting-lock.ts'; +import {cancelVesting} from './src/vesting-cancel.ts'; + +describe("what happens when we add wait interval between lock and cancel?", async () => { + + // https://vitest.dev/guide/test-context.html + beforeEach(async (context) => { + let optimize = false; + + // compile script + const script = await fs.readFile('./src/vesting.js', 'utf8'); + const program = Program.new(script); + const compiledProgram = program.compile(optimize); + const validatorHash = compiledProgram.validatorHash; + const validatorAddress = Address.fromValidatorHash(validatorHash); + + context.program = program; + // + context.validatorHash = validatorHash; + context.validatorAddress = Address.fromValidatorHash(validatorHash); + + // instantiate the Emulator + const minAda = BigInt(2000000); // minimum lovelace needed to send an NFT + const network = new NetworkEmulator(); + + const alice = network.createWallet(BigInt(20000000)); + network.createUtxo(alice, BigInt(50000000)); + const bob = network.createWallet(BigInt(10000000)); + network.tick(BigInt(10)); + + context.alice = alice; + context.bob = bob; + context.network = network; + }) + + it ("documents properties", async ({network, alice, validatorHash}) => { + // https://www.hyperion-bt.org/helios-book/api/reference/address.html?highlight=Address#address + expect(alice.address.toHex().length).toBe(58) + // UTxOs + expect((await alice.utxos)[0].value.dump().lovelace).toBe('20000000'); + expect((await alice.utxos)[1].value.dump().lovelace).toBe('50000000'); + + // https://www.hyperion-bt.org/helios-book/lang/builtins/validatorhash.html?highlight=valida#validatorhash + expect(validatorHash.hex).toBe('e7015c6a1424d748f8241fe3a43b3a382b35dc9ca67320e3ee863dc8') + + + }) + + it ("succeeds cancellation", async ({network, alice, bob, program}) => { + const optimize = false; // need to add it to the context + const compiledScript = program.compile(optimize); + const validatorHash = compiledScript.validatorHash; + const validatorAddress = Address.fromValidatorHash(validatorHash); + + const adaQty = 10; + const duration = 1000000; + await lockAda(network!, alice!, bob!, program, adaQty, duration); + expect((await alice.utxos)[0].value.dump().lovelace).toBe('50000000'); + expect((await alice.utxos)[1].value.dump().lovelace).toBe('9755287'); + + network.tick(BigInt(10)); + + await cancelVesting(network!, alice!, program ); + + const oracle = await alice.utxos; + + // think about which is which. + expect(oracle[2].value.dump().lovelace).toBe('9546007'); + expect(oracle[1].value.dump().lovelace).toBe('10000000');// + expect(oracle[0].value.dump().lovelace).toBe('50000000');// collateral? + }) + it.fails ("Error: tx invalid (not finalized or slot out of range) ", async ({network, alice, bob, program}) => { + const optimize = false; // need to add it to the context + const compiledScript = program.compile(optimize); + const validatorHash = compiledScript.validatorHash; + const validatorAddress = Address.fromValidatorHash(validatorHash); + + const adaQty = 10; + const duration = 1000000; // type: time + await lockAda(network!, alice!, bob!, program, adaQty, duration); + expect((await alice.utxos)[0].value.dump().lovelace).toBe('50000000'); + expect((await alice.utxos)[1].value.dump().lovelace).toBe('9755287'); + + network.tick(BigInt(100000)); //type: number_of_slots + + await cancelVesting(network!, alice!, program ); + + const oracle = await alice.utxos; + + // think about which is which. + expect(oracle[2].value.dump().lovelace).toBe('9546007'); + expect(oracle[1].value.dump().lovelace).toBe('10000000');// + expect(oracle[0].value.dump().lovelace).toBe('50000000');// collateral? + }) + + it ("describes the transaction", async ({network, alice, bob, program}) => { + }) +}) From 56d0c3bc4f4ec13d969f7d7c4987f37d86f1d8a0 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 14 Jun 2023 15:10:49 +0200 Subject: [PATCH 06/17] feat(t/tp): add tests to catch the error if duration is 1e6 then tx fails at slot 10781 --- tests/time-props-vesting.test.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/time-props-vesting.test.ts b/tests/time-props-vesting.test.ts index 932ded4..a6b8cf1 100644 --- a/tests/time-props-vesting.test.ts +++ b/tests/time-props-vesting.test.ts @@ -49,6 +49,11 @@ describe("what happens when we add wait interval between lock and cancel?", asyn context.alice = alice; context.bob = bob; context.network = network; + + const networkParamsFile = await fs.readFile('./src/preprod.json', 'utf8'); + const networkParams = new NetworkParams(JSON.parse(networkParamsFile.toString())); + + context.networkParams = networkParams; }) it ("documents properties", async ({network, alice, validatorHash}) => { @@ -76,7 +81,8 @@ describe("what happens when we add wait interval between lock and cancel?", asyn expect((await alice.utxos)[0].value.dump().lovelace).toBe('50000000'); expect((await alice.utxos)[1].value.dump().lovelace).toBe('9755287'); - network.tick(BigInt(10)); + // https://www.hyperion-bt.org/helios-book/api/reference/fuzzytest.html?highlight=fuzz#fuzzytest + network.tick(BigInt(10780)); await cancelVesting(network!, alice!, program ); @@ -87,19 +93,20 @@ describe("what happens when we add wait interval between lock and cancel?", asyn expect(oracle[1].value.dump().lovelace).toBe('10000000');// expect(oracle[0].value.dump().lovelace).toBe('50000000');// collateral? }) - it.fails ("Error: tx invalid (not finalized or slot out of range) ", async ({network, alice, bob, program}) => { + it.fails ("Error: tx invalid (not finalized or slot out of range) ", async ({network, alice, bob, program, networkParams}) => { const optimize = false; // need to add it to the context const compiledScript = program.compile(optimize); const validatorHash = compiledScript.validatorHash; const validatorAddress = Address.fromValidatorHash(validatorHash); const adaQty = 10; - const duration = 1000000; // type: time + const duration = 1000000; await lockAda(network!, alice!, bob!, program, adaQty, duration); expect((await alice.utxos)[0].value.dump().lovelace).toBe('50000000'); expect((await alice.utxos)[1].value.dump().lovelace).toBe('9755287'); - network.tick(BigInt(100000)); //type: number_of_slots + // https://www.hyperion-bt.org/helios-book/api/reference/fuzzytest.html?highlight=fuzz#fuzzytest + network.tick(BigInt(10781)); await cancelVesting(network!, alice!, program ); From 83a17e3aadbf37403fd51591b04de94be9d2fa67 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 14 Jun 2023 18:31:31 +0200 Subject: [PATCH 07/17] style(units): concat --- tests/unit/context-nesting.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/context-nesting.test.ts b/tests/unit/context-nesting.test.ts index 8e21ffb..9624af9 100644 --- a/tests/unit/context-nesting.test.ts +++ b/tests/unit/context-nesting.test.ts @@ -6,7 +6,7 @@ describe('suite name', (context) => { describe('suite name', (context) => { beforeEach((context) => { - context.foo = 'bar'; + context.foo = 'bar'; }) it('foo', ({foo}) => { expect(foo).toBe('bar') From ac4050a12cf8a82586012d165f13b6a9f994f2d2 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 14 Jun 2023 18:33:18 +0200 Subject: [PATCH 08/17] feat(tests/fuzzy): document Helios method BREAKING CHANGE: #123 --- tests/unit/fuzzy.test.ts | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 tests/unit/fuzzy.test.ts diff --git a/tests/unit/fuzzy.test.ts b/tests/unit/fuzzy.test.ts new file mode 100644 index 0000000..9d7c55a --- /dev/null +++ b/tests/unit/fuzzy.test.ts @@ -0,0 +1,29 @@ +import { describe, expect, it, expectTypeOf, beforeEach, vi } from 'vitest' +import { promises as fs } from 'fs'; +import { + Assets, + FuzzyTest, + MintingPolicyHash, + NetworkEmulator, + Program +} from "@hyperionbt/helios"; + + +import {lockAda} from './src/lockAda.ts'; + +describe("create a network with two wallets of which one has an nft", async () => { + + // https://vitest.dev/guide/test-context.html + beforeEach(async (context) => { + + }) + + it ("checks for Fuzzy", async ({network, alice, bob, mph}) => { + // https://www.hyperion-bt.org/helios-book/api/reference/fuzzytest.html?highlight=fuzzy#fuzzytest + const fuzzy = new FuzzyTest(0,100,false) + expect(await fuzzy.int(0)).toBe(); + + + }) + +}) From 194c04d47a71aefaafbfc4ef9b0f6b6053366aa8 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 15 Jun 2023 07:16:48 +0200 Subject: [PATCH 09/17] fix: disable fuzzy unit test and fix contract name in time-props --- tests/time-props-vesting.test.ts | 2 +- tests/unit/fuzzy.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/time-props-vesting.test.ts b/tests/time-props-vesting.test.ts index a6b8cf1..52db9e4 100644 --- a/tests/time-props-vesting.test.ts +++ b/tests/time-props-vesting.test.ts @@ -26,7 +26,7 @@ describe("what happens when we add wait interval between lock and cancel?", asyn let optimize = false; // compile script - const script = await fs.readFile('./src/vesting.js', 'utf8'); + const script = await fs.readFile('./src/vesting.hl', 'utf8'); const program = Program.new(script); const compiledProgram = program.compile(optimize); const validatorHash = compiledProgram.validatorHash; diff --git a/tests/unit/fuzzy.test.ts b/tests/unit/fuzzy.test.ts index 9d7c55a..f957d67 100644 --- a/tests/unit/fuzzy.test.ts +++ b/tests/unit/fuzzy.test.ts @@ -18,7 +18,7 @@ describe("create a network with two wallets of which one has an nft", async () = }) - it ("checks for Fuzzy", async ({network, alice, bob, mph}) => { + it.fails ("checks for Fuzzy", async ({network, alice, bob, mph}) => { // https://www.hyperion-bt.org/helios-book/api/reference/fuzzytest.html?highlight=fuzzy#fuzzytest const fuzzy = new FuzzyTest(0,100,false) expect(await fuzzy.int(0)).toBe(); From ee4351a9cc1c8dfc16c8370f1686f77b575d9e49 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 21 Jun 2023 10:58:13 +0200 Subject: [PATCH 10/17] test(unit/mintNft): add nft minting transaction BREAKING CHANGE: --- tests/unit/mint-nft.test.ts | 79 +++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 tests/unit/mint-nft.test.ts diff --git a/tests/unit/mint-nft.test.ts b/tests/unit/mint-nft.test.ts new file mode 100644 index 0000000..f987046 --- /dev/null +++ b/tests/unit/mint-nft.test.ts @@ -0,0 +1,79 @@ +import { describe, expect, it, expectTypeOf, beforeEach, vi } from 'vitest' +import { promises as fs } from 'fs'; +import { + hexToBytes, + Assets, + ByteArrayData, + ConstrData, + MintingPolicyHash, + NetworkEmulator, + NetworkParams, + Program, + Tx, + TxOutput, + Value +} from "@hyperionbt/helios"; + + +import {lockAda} from './src/lockAda.ts'; + +describe("create a network with two wallets of which one has an nft", async () => { + + // https://vitest.dev/guide/test-context.html + beforeEach(async (context) => { + + const minAda = BigInt(2000000); // minimum lovelace needed to send an NFT + const network = new NetworkEmulator(); + + const alice = network.createWallet(BigInt(20000000)); + network.createUtxo(alice, BigInt(5000000)); + + network.tick(10n) + + const amt = 5n; + const name = 'name'; + const utxos = await alice.utxos; + const script = await fs.readFile('./src/nft.hl', 'utf8'); + const nftProgram = Program.new(script); + //const nftProgram = new Program(); + nftProgram.parameters = {["TX_ID"] : utxos[0].txId.hex}; + nftProgram.parameters = {["TX_IDX"] : utxos[0].utxoIdx}; + //nftProgram.parameters = {["TN"] : name}; + const nftCompiledProgram = nftProgram.compile(false); + const nftTokenName = ByteArrayData.fromString(name).toHex(); + const tokens: [number[], bigint][] = [[hexToBytes(nftTokenName), amt]]; + + const mintRedeemer = new ConstrData(0, []); + const tx = new Tx() + .addInputs(utxos) + .attachScript(nftCompiledProgram) + .mintTokens( + nftCompiledProgram.mintingPolicyHash, + tokens, + mintRedeemer) + .addOutput(new TxOutput( + (await alice.address), + new Value(minAda, new Assets([[nftCompiledProgram.mintingPolicyHash, tokens]])) + )); + + // expect(tx.dump().body).toBe(); + + const networkParamsFile = await fs.readFile('./src/preprod.json', 'utf8'); + const networkParams = new NetworkParams(JSON.parse(networkParamsFile.toString())); + await tx.finalize(networkParams, alice.address); + const txId = await network.submitTx(tx); + network.tick(10n); + + context.alice = alice; + context.network = network; + + }) + + it ("docs the tx ingridients", async ({network, alice, }) => { + // https://www.hyperion-bt.org/helios-book/api/reference/address.html?highlight=Address#address + expect(alice.address.toHex().length).toBe(58) + expect((await alice.utxos)[0].value.dump().lovelace).toBe('20000000'); + expect(Object.keys((await alice.utxos)[1].value.dump().assets)[0]).toBe(); + }) + +}) From c74db3e44fc08eb004de9780b8da05a0a3ec33ea Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 22 Jun 2023 08:16:14 +0200 Subject: [PATCH 11/17] fix(mint-nft): fix token name and amt in script and test this fixes tx rejected error BREAKING CHANGE: --- src/nft.hl | 4 ++-- tests/unit/mint-nft.test.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/nft.hl b/src/nft.hl index df42df1..a4aacb8 100644 --- a/src/nft.hl +++ b/src/nft.hl @@ -15,7 +15,7 @@ func main(_, ctx: ScriptContext) -> Bool { tt_assetclass: AssetClass = AssetClass::new( mph, - "Thread Token".encode_utf8() + "name".encode_utf8() ); value_minted: Value = tx.minted; @@ -24,4 +24,4 @@ func main(_, ctx: ScriptContext) -> Bool { (input.output_id == outputId).trace("TT2: ") } ) -} \ No newline at end of file +} diff --git a/tests/unit/mint-nft.test.ts b/tests/unit/mint-nft.test.ts index f987046..de79564 100644 --- a/tests/unit/mint-nft.test.ts +++ b/tests/unit/mint-nft.test.ts @@ -30,7 +30,7 @@ describe("create a network with two wallets of which one has an nft", async () = network.tick(10n) - const amt = 5n; + const amt = 1n; const name = 'name'; const utxos = await alice.utxos; const script = await fs.readFile('./src/nft.hl', 'utf8'); From 6e470aac8ed3b58eb4f5d45e714d340027fc2017 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 22 Jun 2023 10:22:35 +0200 Subject: [PATCH 12/17] test(mint-nft.test): change expected value in the test --- tests/unit/mint-nft.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/mint-nft.test.ts b/tests/unit/mint-nft.test.ts index de79564..265ba22 100644 --- a/tests/unit/mint-nft.test.ts +++ b/tests/unit/mint-nft.test.ts @@ -72,7 +72,7 @@ describe("create a network with two wallets of which one has an nft", async () = it ("docs the tx ingridients", async ({network, alice, }) => { // https://www.hyperion-bt.org/helios-book/api/reference/address.html?highlight=Address#address expect(alice.address.toHex().length).toBe(58) - expect((await alice.utxos)[0].value.dump().lovelace).toBe('20000000'); + expect((await alice.utxos)[0].value.dump().lovelace).toBe('2000000'); expect(Object.keys((await alice.utxos)[1].value.dump().assets)[0]).toBe(); }) From 0ce0de0cbe0acea4898ff76409e23c873197a511 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 22 Jun 2023 10:28:35 +0200 Subject: [PATCH 13/17] feat(mintNft): add name to the script --- src/nft.hl | 1 + tests/unit/mint-nft.test.ts | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/nft.hl b/src/nft.hl index a4aacb8..daa6dcf 100644 --- a/src/nft.hl +++ b/src/nft.hl @@ -8,6 +8,7 @@ const TX_ID: ByteArray = #7c873bf399ed9255e38f9d897e835f017377320794a3ecd4f1d045 const txId: TxId = TxId::new(TX_ID) const TX_IDX: Int = 0 const outputId: TxOutputId = TxOutputId::new(txId, TX_IDX) +const TN: String = "" func main(_, ctx: ScriptContext) -> Bool { tx: Tx = ctx.tx; diff --git a/tests/unit/mint-nft.test.ts b/tests/unit/mint-nft.test.ts index 265ba22..1f1987f 100644 --- a/tests/unit/mint-nft.test.ts +++ b/tests/unit/mint-nft.test.ts @@ -38,7 +38,7 @@ describe("create a network with two wallets of which one has an nft", async () = //const nftProgram = new Program(); nftProgram.parameters = {["TX_ID"] : utxos[0].txId.hex}; nftProgram.parameters = {["TX_IDX"] : utxos[0].utxoIdx}; - //nftProgram.parameters = {["TN"] : name}; + nftProgram.parameters = {["TN"] : name}; const nftCompiledProgram = nftProgram.compile(false); const nftTokenName = ByteArrayData.fromString(name).toHex(); const tokens: [number[], bigint][] = [[hexToBytes(nftTokenName), amt]]; From 4faa03beacef9dad4d5c3dcc851ca48cc73bbcc0 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 22 Jun 2023 10:29:32 +0200 Subject: [PATCH 14/17] feat(mintNft): change amount of token minted get an error: tx rejected BREAKING CHANGE: --- tests/unit/mint-nft.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/mint-nft.test.ts b/tests/unit/mint-nft.test.ts index 1f1987f..c323460 100644 --- a/tests/unit/mint-nft.test.ts +++ b/tests/unit/mint-nft.test.ts @@ -30,7 +30,7 @@ describe("create a network with two wallets of which one has an nft", async () = network.tick(10n) - const amt = 1n; + const amt = 5n; const name = 'name'; const utxos = await alice.utxos; const script = await fs.readFile('./src/nft.hl', 'utf8'); From 64bc1ff0cda6571962d1427144afc82e0ba7d996 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 22 Jun 2023 10:30:57 +0200 Subject: [PATCH 15/17] feat(mintNFt): show that same error occurs with a different parameter BREAKING CHANGE: --- tests/unit/mint-nft.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/mint-nft.test.ts b/tests/unit/mint-nft.test.ts index c323460..549ea8d 100644 --- a/tests/unit/mint-nft.test.ts +++ b/tests/unit/mint-nft.test.ts @@ -30,8 +30,8 @@ describe("create a network with two wallets of which one has an nft", async () = network.tick(10n) - const amt = 5n; - const name = 'name'; + const amt = 1n; + const name = 'abc'; const utxos = await alice.utxos; const script = await fs.readFile('./src/nft.hl', 'utf8'); const nftProgram = Program.new(script); From cc68372c28df82536b0d41f30b93de1ef7f5035a Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 22 Jun 2023 10:33:31 +0200 Subject: [PATCH 16/17] fix(mintNft): add parameter into the script --- src/nft.hl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nft.hl b/src/nft.hl index daa6dcf..49c3c31 100644 --- a/src/nft.hl +++ b/src/nft.hl @@ -16,7 +16,7 @@ func main(_, ctx: ScriptContext) -> Bool { tt_assetclass: AssetClass = AssetClass::new( mph, - "name".encode_utf8() + TN.encode_utf8() ); value_minted: Value = tx.minted; From fe327a400bf5d2c2424f58140c804c7443ae61c1 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 22 Jun 2023 10:45:23 +0200 Subject: [PATCH 17/17] feat(mintNft): add amt parameter and checks --- src/nft.hl | 3 ++- tests/unit/mint-nft.test.ts | 17 ++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/nft.hl b/src/nft.hl index 49c3c31..aa0038a 100644 --- a/src/nft.hl +++ b/src/nft.hl @@ -9,6 +9,7 @@ const txId: TxId = TxId::new(TX_ID) const TX_IDX: Int = 0 const outputId: TxOutputId = TxOutputId::new(txId, TX_IDX) const TN: String = "" +const AMT: Int = 1 func main(_, ctx: ScriptContext) -> Bool { tx: Tx = ctx.tx; @@ -20,7 +21,7 @@ func main(_, ctx: ScriptContext) -> Bool { ); value_minted: Value = tx.minted; - (value_minted == Value::new(tt_assetclass, 1)).trace("TT1: ") && + (value_minted == Value::new(tt_assetclass, AMT)).trace("TT1: ") && tx.inputs.any((input: TxInput) -> Bool { (input.output_id == outputId).trace("TT2: ") } diff --git a/tests/unit/mint-nft.test.ts b/tests/unit/mint-nft.test.ts index 549ea8d..e7c2b81 100644 --- a/tests/unit/mint-nft.test.ts +++ b/tests/unit/mint-nft.test.ts @@ -22,15 +22,17 @@ describe("create a network with two wallets of which one has an nft", async () = // https://vitest.dev/guide/test-context.html beforeEach(async (context) => { - const minAda = BigInt(2000000); // minimum lovelace needed to send an NFT const network = new NetworkEmulator(); + const networkParamsFile = await fs.readFile('./src/preprod.json', 'utf8'); + const networkParams = new NetworkParams(JSON.parse(networkParamsFile.toString())); + const minAda = BigInt(2000000); // minimum lovelace needed to send an NFT const alice = network.createWallet(BigInt(20000000)); network.createUtxo(alice, BigInt(5000000)); network.tick(10n) - const amt = 1n; + const amt = 5n; const name = 'abc'; const utxos = await alice.utxos; const script = await fs.readFile('./src/nft.hl', 'utf8'); @@ -39,6 +41,7 @@ describe("create a network with two wallets of which one has an nft", async () = nftProgram.parameters = {["TX_ID"] : utxos[0].txId.hex}; nftProgram.parameters = {["TX_IDX"] : utxos[0].utxoIdx}; nftProgram.parameters = {["TN"] : name}; + nftProgram.parameters = {["AMT"] : amt}; const nftCompiledProgram = nftProgram.compile(false); const nftTokenName = ByteArrayData.fromString(name).toHex(); const tokens: [number[], bigint][] = [[hexToBytes(nftTokenName), amt]]; @@ -56,24 +59,24 @@ describe("create a network with two wallets of which one has an nft", async () = new Value(minAda, new Assets([[nftCompiledProgram.mintingPolicyHash, tokens]])) )); - // expect(tx.dump().body).toBe(); - const networkParamsFile = await fs.readFile('./src/preprod.json', 'utf8'); - const networkParams = new NetworkParams(JSON.parse(networkParamsFile.toString())); await tx.finalize(networkParams, alice.address); const txId = await network.submitTx(tx); network.tick(10n); context.alice = alice; context.network = network; + context.mph = nftCompiledProgram.mintingPolicyHash.hex; + context.amt = amt; }) - it ("docs the tx ingridients", async ({network, alice, }) => { + it ("asserts properties", async ({network, alice, amt, mph }) => { // https://www.hyperion-bt.org/helios-book/api/reference/address.html?highlight=Address#address expect(alice.address.toHex().length).toBe(58) expect((await alice.utxos)[0].value.dump().lovelace).toBe('2000000'); - expect(Object.keys((await alice.utxos)[1].value.dump().assets)[0]).toBe(); + expect((await alice.utxos)[1].value.dump().lovelace).toBe('22753044'); + expect((await alice.utxos)[0].value.dump().assets[mph][616263]).toBe(amt.toString()); }) })