-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nft minting #126
Merged
nft minting #126
Changes from 11 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a7c54cc
docs(template): change test description
aleeusgr 175c3c1
docs(t/cv): refactor
aleeusgr 4eb846a
refactor(t/vc): sort things
aleeusgr b4e6024
style(t/cv): rm line
aleeusgr 2073364
test(t/tp): add a check for validity interval
aleeusgr 56d0c3b
feat(t/tp): add tests to catch the error
aleeusgr 83a17e3
style(units): concat
aleeusgr ac4050a
feat(tests/fuzzy): document Helios method
aleeusgr 5a9741a
feat: merge main into time
aleeusgr 194c04d
fix: disable fuzzy unit test and fix contract name in time-props
aleeusgr ee4351a
test(unit/mintNft): add nft minting transaction
aleeusgr c74db3e
fix(mint-nft): fix token name and amt in script and test
aleeusgr 6e470aa
test(mint-nft.test): change expected value in the test
aleeusgr 0ce0de0
feat(mintNft): add name to the script
aleeusgr 4faa03b
feat(mintNft): change amount of token minted
aleeusgr 64bc1ff
feat(mintNFt): show that same error occurs with a different parameter
aleeusgr cc68372
fix(mintNft): add parameter into the script
aleeusgr fe327a4
feat(mintNft): add amt parameter and checks
aleeusgr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
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.hl', '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; | ||
|
||
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}) => { | ||
// 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'); | ||
|
||
// https://www.hyperion-bt.org/helios-book/api/reference/fuzzytest.html?highlight=fuzz#fuzzytest | ||
network.tick(BigInt(10780)); | ||
|
||
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, 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; | ||
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'); | ||
|
||
// https://www.hyperion-bt.org/helios-book/api/reference/fuzzytest.html?highlight=fuzz#fuzzytest | ||
network.tick(BigInt(10781)); | ||
|
||
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}) => { | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.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(); | ||
|
||
|
||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and sure enough, changing to 1n solves the problem