-
Notifications
You must be signed in to change notification settings - Fork 2
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
Vesting #100
Closed
Vesting #100
Changes from 129 commits
Commits
Show all changes
137 commits
Select commit
Hold shift + click to select a range
0752e56
lley154
aleeusgr 144aaa5
add some lucid code
aleeusgr 55f6202
test
aleeusgr 75241c3
disable old tests, emulate-something
aleeusgr b17cd0a
dummy test, lucid import
aleeusgr f87199d
interesting error message
aleeusgr 1bed3c4
add code from first test
aleeusgr 9f31435
pass
aleeusgr 6ec5a28
refactoring
aleeusgr 580a178
testing api
aleeusgr 853d2f8
comment
aleeusgr 15e5cbb
add lucid code for minting nfts
aleeusgr 6b64083
comment
aleeusgr c1cf2dd
enable helios test
aleeusgr e26ca18
error, lucid
aleeusgr 3896a4f
revert
aleeusgr dbfc7f1
test: instantiate an emulator. How do I use beforeEach?
aleeusgr 94e72cf
failed experiments
aleeusgr 899073a
restored logging
aleeusgr a2f6067
add minting transaction
aleeusgr 082fbc5
ehm,
aleeusgr 86bad02
clean up a bit
aleeusgr d7c6e0c
idea
aleeusgr eed95ab
minting -> function, added wait interval
aleeusgr e30451e
goal
aleeusgr 00b980d
create new test
aleeusgr 5c96dd1
renaming
aleeusgr a9aad72
empty test
aleeusgr d67fd87
refactoring
aleeusgr d903f2d
gc
aleeusgr f6fb78d
clean
aleeusgr 28c169a
seed
aleeusgr 5039821
error object Object to BigInt
aleeusgr af4ea65
transaction building function
aleeusgr 7610ef5
lucid.newTx.payToContract fails to complete
aleeusgr c6f32e8
clean up
aleeusgr 732deb5
naming
aleeusgr 1977803
doesnt make sense
aleeusgr cfb967e
dont need seed anymore
aleeusgr 5d724a4
if I move mintTx out to Describe, get same error.
aleeusgr 880fdc6
Merge branch 'refactor' into interact-with-plutus-script
aleeusgr 62eebd2
pass
aleeusgr a9204ad
rename
aleeusgr b457c9c
look up import statement
aleeusgr 5637853
pass
aleeusgr 7410e23
disable passing test
aleeusgr 86ae0ed
stuck
aleeusgr 3f0db1e
lint
aleeusgr a5e4644
got cborHex from Helios
aleeusgr eec74e5
my utxo changes, now I need to withdraw from the contract
aleeusgr 4a5284e
why my balance does not change?
aleeusgr 14839bd
I am not sure what happens, but checks are passing
aleeusgr 857cac2
naming
aleeusgr 5875f60
naming, sanity check
aleeusgr 5040e99
changelog
aleeusgr 5c7981e
sanity check
aleeusgr dc03844
development will become main
aleeusgr 9c9dd69
reflect
aleeusgr e5e074f
moved helios source to separate file
aleeusgr c04ffc9
removed print on passing tests
aleeusgr 72d50e4
naming
aleeusgr ce9bf4b
need to look up stuff
aleeusgr b0ece42
pass
aleeusgr f313804
added redeemUtxo to integration test
aleeusgr 33b40af
remove extra prints
aleeusgr ea5af2b
renaming and reflection
aleeusgr a6d681c
new test
aleeusgr 25b5d80
look at vesting first
aleeusgr cac21cb
rfl
aleeusgr c11f8de
deprecate
aleeusgr 11f3f98
matching keyhash
aleeusgr 497b1ca
naming
aleeusgr 3d8527d
testing tx
aleeusgr cf95cdb
matching keyhash pass
aleeusgr 27477b8
rfl
aleeusgr d4fc662
take a look at the vesting example, can I make it work?
aleeusgr 0956dcd
explore vesting contract
aleeusgr 1e0f597
redeem, comment
aleeusgr 3625e83
I dunno what Im doing
aleeusgr 0a91d68
datum -> lockADA, redeemer -> redeemUTXO
aleeusgr f52175a
helios syntax highlighting, comments
aleeusgr 6df30bb
comments -> Issue
aleeusgr 852bfa6
test code, get error
aleeusgr 88d955f
clean up
aleeusgr 3e2f07e
run the emulator
aleeusgr ab86c1c
redeem matching keyhash
aleeusgr b89ed85
Merge branch 'redeem-vesting' into development
aleeusgr a1ad118
what is my high level story?
aleeusgr fbe3083
redundant
aleeusgr bcac31c
review repo
aleeusgr f557588
Merge branch 'helios-emulator' into development
aleeusgr 53f1473
condition on emulator creation
aleeusgr 358e7f6
fixed overt error
aleeusgr e836f10
rfl
aleeusgr 7d1c7f7
add emulator unit test
aleeusgr 4fd3a0c
typo
aleeusgr c10d2bf
naming
aleeusgr 57a725f
naimng
aleeusgr 8ed31ed
going in circles
aleeusgr 5a79321
Address?
aleeusgr e60e6f6
sanity check
aleeusgr e58dc1a
what is Address?
aleeusgr 824206a
sanity check pass
aleeusgr a6d5cb9
format
aleeusgr 44fe91c
fair naming
aleeusgr a2b2d83
suggestions
aleeusgr 7d6dc05
suggestions
aleeusgr d21317c
circles
aleeusgr 0078dc9
highlights
aleeusgr c5c61bf
working code example
aleeusgr 5bf1efb
better example
aleeusgr a15678b
adding my working code
aleeusgr a97a233
naming?
aleeusgr d17f330
add more
aleeusgr 2f811a1
comments
aleeusgr 669ee8d
redundancy
aleeusgr 4a3f107
rlf
aleeusgr a8ad89a
reorg
aleeusgr b8f5d15
test template
aleeusgr a984107
docs
aleeusgr 99163d3
fix: commented out code that broke github actions
aleeusgr 23abafa
feat(helios): a function to provide contract endpoints to the emulator
aleeusgr 6272217
feat(helios-program.test): copy suggested template and make test pass
aleeusgr 20d3026
test(tests/helios-program): test properties on api method outputs
aleeusgr 66fcfd7
style(tests/helios-program): describe it
aleeusgr 371aa73
refactor(naming-tests): helios.Program, but why this association? in …
aleeusgr 803e0a3
feat(helios-program-doc.test.ts): added beforeEach to the test
aleeusgr b01807c
refactor(/tests-/src): removed non-working code and disabled running …
aleeusgr dd9c6cf
feat(tests/helios-vesting): added emulator instantiation with a test …
aleeusgr 3fcd06f
refactor: deleted old tests to simplify code review process
aleeusgr 8e50fde
Merge branch 'development' into vesting
aleeusgr 201fbc6
fix(helios-program-doc.test): changed matching keyhash to vesting to …
aleeusgr 8f5cc42
Merge branch 'development' into vesting
aleeusgr 59a5e2d
feat(helios-vesting.test): added Datum
aleeusgr 1c6dcc8
feat(helios-vesting.test): building the transaction
aleeusgr 8b5fa1e
feat(helios-vesting.test): completed the tx
aleeusgr ed7eee2
style(helios-vestin.test): comments and removing unused parts
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 |
---|---|---|
@@ -1,5 +1,64 @@ | ||
# potential-robot | ||
[source](https://github.com/koralabs/handles-personalization/tree/master/simple_example_wth_tests) | ||
|
||
An option smart contract; | ||
lockAda (owner Pkh, nft, deadline); | ||
claimAda (nft): not after deadline? | ||
|
||
I'll suggest starting a lightweight outline of testable expectations. | ||
|
||
Formatting test files using that kind of outline provides good organization and structure for the testing code. | ||
|
||
outline in test DSL: | ||
|
||
- [ ] | ||
```javascript | ||
describe("vesting contract"), () => { | ||
describe("contract initiation", () => { | ||
it("holds assets for vesting", async() => { | ||
}) | ||
it("lets the initiator take their own funds back, until the contract is claimed", async () => {}) | ||
}) | ||
describe("contract claim", async() => { | ||
it("allows the recipient to mint a claim token they can hold in their wallet" async() => { | ||
}) | ||
it("doesn't let the initiator withdraw funds once claimed", async() => { | ||
}) | ||
}) | ||
|
||
describe("gradual maturation", () => { | ||
... | ||
}) | ||
|
||
describe("reclaiming funds after long period of inactivity" () => { | ||
... | ||
}) | ||
}) | ||
``` | ||
|
||
- [ ] | ||
```javascript | ||
describe("vesting contract", () => { | ||
let vestingProgram, initiatorWallet, recipientWallet; | ||
beforeEach(() => { | ||
vestingProgram = new helios.Program( ... ); | ||
... | ||
}) | ||
it ("tests things while reusing provided `vestingProgram`", async () => { | ||
... | ||
}) | ||
}) | ||
``` | ||
- [ ] | ||
```javascript | ||
it("works with datumHash and datum at spend time") | ||
it("works with inlineDatum and no special datum at spend time") | ||
``` | ||
|
||
|
||
|
||
`npm install` | ||
`npm test` | ||
|
||
references: | ||
https://github.com/koralabs/handles-personalization/tree/master/simple_example_wth_tests | ||
https://github.com/lley154/helios-examples/tree/main/vitest |
aleeusgr marked this conversation as resolved.
Show resolved
Hide resolved
|
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,21 @@ | ||
import { assert, expect, test } from 'vitest' | ||
|
||
// Edit an assertion and save to see HMR in action | ||
|
||
test('Math.sqrt()', () => { | ||
expect(Math.sqrt(4)).toBe(2) | ||
expect(Math.sqrt(144)).toBe(12) | ||
expect(Math.sqrt(2)).toBe(Math.SQRT2) | ||
}) | ||
|
||
test('JSON', () => { | ||
const input = { | ||
foo: 'hello', | ||
bar: 'world', | ||
} | ||
|
||
const output = JSON.stringify(input) | ||
|
||
expect(output).eq('{"foo":"hello","bar":"world"}') | ||
assert.deepEqual(JSON.parse(output), input, 'matches original') | ||
}) |
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,144 @@ | ||
import { describe, expect, it, vi } from 'vitest' | ||
import { promises as fs } from 'fs'; | ||
import { | ||
Assets, | ||
ConstrData, | ||
MintingPolicyHash, | ||
NetworkEmulator, | ||
NetworkParams, | ||
Program, | ||
Value, | ||
textToBytes, | ||
TxOutput, | ||
Tx, | ||
} from "@hyperionbt/helios"; | ||
|
||
describe('Creates Helios Emulator and adds an nft to a wallet', () => { | ||
|
||
const main = async () => { | ||
|
||
let optimize = false; | ||
const minAda = BigInt(2000000); // minimum lovelace needed to send an NFT | ||
try { | ||
// Create an Instance of NetworkEmulator | ||
const network = new NetworkEmulator(); | ||
|
||
// Create a Wallet - we add 10ADA to start | ||
const alice = network.createWallet(BigInt(10000000)); | ||
|
||
// Add an additional lovelace only UTXO | ||
network.createUtxo(alice, BigInt(5000000)); | ||
|
||
// Create a Test Asset | ||
const testAsset = new Assets(); | ||
testAsset.addComponent( | ||
MintingPolicyHash.fromHex( | ||
'16aa5486dab6527c4697387736ae449411c03dcd20a3950453e6779c' | ||
), | ||
Array.from(new TextEncoder().encode('Test Asset Name')), | ||
BigInt(1) | ||
); | ||
|
||
// Add additional Token to the wallet | ||
network.createUtxo(alice, BigInt(2000000), testAsset); | ||
|
||
// Now lets tick the network on 10 slots, | ||
// this will allow the UTxOs to be created from Genisis | ||
network.tick(BigInt(10)); | ||
|
||
// Now we are able to get the UTxOs in Alices wallet | ||
const utxos = await network.getUtxos(alice.address); | ||
console.log("************ PRE-TEST ************"); | ||
|
||
console.log("Wallet UTXOs:"); | ||
for (const utxo of utxos) { | ||
console.log("txId", utxo.txId.hex + "#" + utxo.utxoIdx); | ||
console.log("value", utxo.value.dump()); | ||
} | ||
|
||
// Pull in the NFT minting script, update params and compile | ||
const nftScript = await fs.readFile('./src/nft.hl', 'utf8'); | ||
const nftProgram = Program.new(nftScript); | ||
nftProgram.parameters = {["TX_ID"] : utxos[0].txId.hex}; | ||
nftProgram.parameters = {["TX_IDX"] : utxos[0].utxoIdx}; | ||
const nftCompiledProgram = nftProgram.compile(optimize); | ||
const nftMPH = nftCompiledProgram.mintingPolicyHash; | ||
|
||
// Start building the transaction | ||
const tx = new Tx(); | ||
|
||
// Add the UTXO as inputs | ||
tx.addInputs(utxos); | ||
|
||
// Add the script as a witness to the transaction | ||
tx.attachScript(nftCompiledProgram); | ||
|
||
// Create an empty Redeemer because we must always send a Redeemer with | ||
// a plutus script transaction even if we don't actually use it. | ||
const nftRedeemer = new ConstrData(0, []); | ||
const token = [[textToBytes("Thread Token"), BigInt(1)]]; | ||
|
||
// Add the mint to the tx | ||
tx.mintTokens( | ||
nftMPH, | ||
token, | ||
nftRedeemer | ||
) | ||
|
||
// Attach the output with the minted nft to the destination address | ||
tx.addOutput(new TxOutput( | ||
alice.address, | ||
new Value(minAda, new Assets([[nftMPH, token]])) | ||
)); | ||
|
||
// Network Parameters | ||
const networkParamsFile = await fs.readFile('./src/preprod.json', 'utf8'); | ||
const networkParams = new NetworkParams(JSON.parse(networkParamsFile.toString())); | ||
|
||
console.log(""); | ||
console.log("************ EXECUTE SMART CONTRACT ************"); | ||
await tx.finalize(networkParams, alice.address, utxos); | ||
|
||
console.log(""); | ||
console.log("************ SUBMIT TX ************"); | ||
// Submit Tx to the network | ||
const txId = await network.submitTx(tx); | ||
console.log("TxId", txId.dump()); | ||
|
||
// Tick the network on 10 more slots, | ||
network.tick(BigInt(10)); | ||
|
||
const utxosFinal = await network.getUtxos(alice.address); | ||
console.log(""); | ||
console.log("************ POST-TEST ************"); | ||
console.log("Wallet UTXOs:"); | ||
for (const utxo of utxosFinal) { | ||
console.log("txId", utxo.txId.hex + "#" + utxo.utxoIdx); | ||
console.log("value", utxo.value.dump()); | ||
} | ||
|
||
return utxosFinal[2].value.dump().lovelace == '13676369' | ||
} catch (err) { | ||
console.error("something failed:", err); | ||
return false; | ||
} | ||
} | ||
|
||
it('adds logging', async () => { | ||
|
||
const logMsgs = new Set(); | ||
const logSpy = vi.spyOn(global.console, 'log') | ||
.mockImplementation((msg) => { logMsgs.add(msg); }); | ||
|
||
let mainStatus = await main(); | ||
logSpy.mockRestore(); | ||
if (!mainStatus) { | ||
console.log("Smart Contract Messages: ", logMsgs); | ||
} | ||
expect(mainStatus).toBe(true); | ||
console.log(logMsgs); | ||
|
||
}) | ||
|
||
}) | ||
|
aleeusgr marked this conversation as resolved.
Show resolved
Hide resolved
|
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,69 @@ | ||
import { describe, expect, it, vi } from 'vitest' | ||
import { promises as fs } from 'fs'; | ||
import { | ||
Assets, | ||
Address, | ||
ConstrData, | ||
MintingPolicyHash, | ||
NetworkEmulator, | ||
NetworkParams, | ||
Program, | ||
Value, | ||
textToBytes, | ||
TxOutput, | ||
Tx, | ||
} from "@hyperionbt/helios"; | ||
|
||
describe('Submits a transaction to a validator address', () => { | ||
|
||
const main = async () => { | ||
|
||
let optimize = false; | ||
const minAda = BigInt(2000000); // minimum lovelace needed to send an NFT | ||
try { | ||
const network = new NetworkEmulator(); | ||
|
||
const alice = network.createWallet(BigInt(10000000)); | ||
|
||
network.createUtxo(alice, BigInt(5000000)); | ||
|
||
network.tick(BigInt(10)); | ||
|
||
// Now we are able to get the UTxOs in Alices wallet | ||
|
||
const script = await fs.readFile('./src/owner-only.hl', 'utf8'); | ||
const program = Program.new(script); | ||
const compiledProgram = program.compile(optimize); | ||
|
||
const validatorHash = compiledProgram.validatorHash; | ||
// https://www.hyperion-bt.org/helios-book/lang/builtins/address.html#address | ||
const validatorAddress = Address.fromValidatorHash(validatorHash); | ||
|
||
const utxosFinal = await network.getUtxos(alice.address); | ||
|
||
return utxosFinal[1].value.dump().lovelace == '5000000' && validatorAddress.toBech32() == 'addr_test1wq8jn3u0ts654lp6ltvyju7nflcm5qegukqukuhc4jdxhag7ku5n4' | ||
|
||
} catch (err) { | ||
console.error("something failed:", err); | ||
return false; | ||
} | ||
} | ||
|
||
it('adds logging', async () => { | ||
|
||
const logMsgs = new Set(); | ||
const logSpy = vi.spyOn(global.console, 'log') | ||
.mockImplementation((msg) => { logMsgs.add(msg); }); | ||
|
||
let mainStatus = await main(); | ||
logSpy.mockRestore(); | ||
if (!mainStatus) { | ||
console.log("Smart Contract Messages: ", logMsgs); | ||
} | ||
expect(mainStatus).toBe(true); | ||
console.log(logMsgs); | ||
|
||
}) | ||
|
||
}) | ||
|
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.
delete 3,4,5