Skip to content

Commit

Permalink
feat(mintNft): add amt parameter and checks
Browse files Browse the repository at this point in the history
  • Loading branch information
aleeusgr committed Jun 22, 2023
1 parent cc68372 commit fe327a4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/nft.hl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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: ")
}
Expand Down
17 changes: 10 additions & 7 deletions tests/unit/mint-nft.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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]];
Expand All @@ -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());
})

})

0 comments on commit fe327a4

Please sign in to comment.