Skip to content
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
wants to merge 137 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
0752e56
lley154
aleeusgr Apr 18, 2023
144aaa5
add some lucid code
aleeusgr Apr 19, 2023
55f6202
test
aleeusgr Apr 19, 2023
75241c3
disable old tests, emulate-something
aleeusgr Apr 19, 2023
b17cd0a
dummy test, lucid import
aleeusgr Apr 20, 2023
f87199d
interesting error message
aleeusgr Apr 20, 2023
1bed3c4
add code from first test
aleeusgr Apr 20, 2023
9f31435
pass
aleeusgr Apr 20, 2023
6ec5a28
refactoring
aleeusgr Apr 24, 2023
580a178
testing api
aleeusgr Apr 25, 2023
853d2f8
comment
aleeusgr Apr 25, 2023
15e5cbb
add lucid code for minting nfts
aleeusgr Apr 25, 2023
6b64083
comment
aleeusgr Apr 25, 2023
c1cf2dd
enable helios test
aleeusgr Apr 25, 2023
e26ca18
error, lucid
aleeusgr Apr 25, 2023
3896a4f
revert
aleeusgr Apr 25, 2023
dbfc7f1
test: instantiate an emulator. How do I use beforeEach?
aleeusgr Apr 26, 2023
94e72cf
failed experiments
aleeusgr Apr 26, 2023
899073a
restored logging
aleeusgr Apr 26, 2023
a2f6067
add minting transaction
aleeusgr Apr 26, 2023
082fbc5
ehm,
aleeusgr Apr 26, 2023
86bad02
clean up a bit
aleeusgr Apr 27, 2023
d7c6e0c
idea
aleeusgr Apr 27, 2023
eed95ab
minting -> function, added wait interval
aleeusgr Apr 27, 2023
e30451e
goal
aleeusgr Apr 29, 2023
00b980d
create new test
aleeusgr Apr 29, 2023
5c96dd1
renaming
aleeusgr Apr 29, 2023
a9aad72
empty test
aleeusgr Apr 29, 2023
d67fd87
refactoring
aleeusgr Apr 29, 2023
d903f2d
gc
aleeusgr Apr 29, 2023
f6fb78d
clean
aleeusgr Apr 30, 2023
28c169a
seed
aleeusgr Apr 30, 2023
5039821
error object Object to BigInt
aleeusgr Apr 30, 2023
af4ea65
transaction building function
aleeusgr Apr 30, 2023
7610ef5
lucid.newTx.payToContract fails to complete
aleeusgr Apr 30, 2023
c6f32e8
clean up
aleeusgr Apr 30, 2023
732deb5
naming
aleeusgr Apr 30, 2023
1977803
doesnt make sense
aleeusgr May 1, 2023
cfb967e
dont need seed anymore
aleeusgr May 1, 2023
5d724a4
if I move mintTx out to Describe, get same error.
aleeusgr May 1, 2023
880fdc6
Merge branch 'refactor' into interact-with-plutus-script
aleeusgr May 1, 2023
62eebd2
pass
aleeusgr May 1, 2023
a9204ad
rename
aleeusgr May 1, 2023
b457c9c
look up import statement
aleeusgr May 1, 2023
5637853
pass
aleeusgr May 1, 2023
7410e23
disable passing test
aleeusgr May 1, 2023
86ae0ed
stuck
aleeusgr May 1, 2023
3f0db1e
lint
aleeusgr May 1, 2023
a5e4644
got cborHex from Helios
aleeusgr May 1, 2023
eec74e5
my utxo changes, now I need to withdraw from the contract
aleeusgr May 1, 2023
4a5284e
why my balance does not change?
aleeusgr May 1, 2023
14839bd
I am not sure what happens, but checks are passing
aleeusgr May 1, 2023
857cac2
naming
aleeusgr May 1, 2023
5875f60
naming, sanity check
aleeusgr May 1, 2023
5040e99
changelog
aleeusgr May 1, 2023
5c7981e
sanity check
aleeusgr May 2, 2023
dc03844
development will become main
aleeusgr May 2, 2023
9c9dd69
reflect
aleeusgr May 2, 2023
e5e074f
moved helios source to separate file
aleeusgr May 2, 2023
c04ffc9
removed print on passing tests
aleeusgr May 2, 2023
72d50e4
naming
aleeusgr May 2, 2023
ce9bf4b
need to look up stuff
aleeusgr May 2, 2023
b0ece42
pass
aleeusgr May 3, 2023
f313804
added redeemUtxo to integration test
aleeusgr May 3, 2023
33b40af
remove extra prints
aleeusgr May 3, 2023
ea5af2b
renaming and reflection
aleeusgr May 3, 2023
a6d681c
new test
aleeusgr May 4, 2023
25b5d80
look at vesting first
aleeusgr May 4, 2023
cac21cb
rfl
aleeusgr May 4, 2023
c11f8de
deprecate
aleeusgr May 4, 2023
11f3f98
matching keyhash
aleeusgr May 4, 2023
497b1ca
naming
aleeusgr May 4, 2023
3d8527d
testing tx
aleeusgr May 4, 2023
cf95cdb
matching keyhash pass
aleeusgr May 4, 2023
27477b8
rfl
aleeusgr May 4, 2023
d4fc662
take a look at the vesting example, can I make it work?
aleeusgr May 5, 2023
0956dcd
explore vesting contract
aleeusgr May 5, 2023
1e0f597
redeem, comment
aleeusgr May 5, 2023
3625e83
I dunno what Im doing
aleeusgr May 5, 2023
0a91d68
datum -> lockADA, redeemer -> redeemUTXO
aleeusgr May 5, 2023
f52175a
helios syntax highlighting, comments
aleeusgr May 5, 2023
6df30bb
comments -> Issue
aleeusgr May 5, 2023
852bfa6
test code, get error
aleeusgr May 9, 2023
88d955f
clean up
aleeusgr May 9, 2023
3e2f07e
run the emulator
aleeusgr May 9, 2023
ab86c1c
redeem matching keyhash
aleeusgr May 9, 2023
b89ed85
Merge branch 'redeem-vesting' into development
aleeusgr May 9, 2023
a1ad118
what is my high level story?
aleeusgr May 9, 2023
fbe3083
redundant
aleeusgr May 9, 2023
bcac31c
review repo
aleeusgr May 9, 2023
f557588
Merge branch 'helios-emulator' into development
aleeusgr May 9, 2023
53f1473
condition on emulator creation
aleeusgr May 9, 2023
358e7f6
fixed overt error
aleeusgr May 9, 2023
e836f10
rfl
aleeusgr May 13, 2023
7d1c7f7
add emulator unit test
aleeusgr May 13, 2023
4fd3a0c
typo
aleeusgr May 13, 2023
c10d2bf
naming
aleeusgr May 13, 2023
57a725f
naimng
aleeusgr May 13, 2023
8ed31ed
going in circles
aleeusgr May 13, 2023
5a79321
Address?
aleeusgr May 13, 2023
e60e6f6
sanity check
aleeusgr May 13, 2023
e58dc1a
what is Address?
aleeusgr May 13, 2023
824206a
sanity check pass
aleeusgr May 13, 2023
a6d5cb9
format
aleeusgr May 13, 2023
44fe91c
fair naming
aleeusgr May 13, 2023
a2b2d83
suggestions
aleeusgr May 16, 2023
7d6dc05
suggestions
aleeusgr May 16, 2023
d21317c
circles
aleeusgr May 16, 2023
0078dc9
highlights
aleeusgr May 16, 2023
c5c61bf
working code example
aleeusgr May 16, 2023
5bf1efb
better example
aleeusgr May 16, 2023
a15678b
adding my working code
aleeusgr May 16, 2023
a97a233
naming?
aleeusgr May 16, 2023
d17f330
add more
aleeusgr May 16, 2023
2f811a1
comments
aleeusgr May 16, 2023
669ee8d
redundancy
aleeusgr May 16, 2023
4a3f107
rlf
aleeusgr May 16, 2023
a8ad89a
reorg
aleeusgr May 17, 2023
b8f5d15
test template
aleeusgr May 17, 2023
a984107
docs
aleeusgr May 17, 2023
99163d3
fix: commented out code that broke github actions
aleeusgr May 17, 2023
23abafa
feat(helios): a function to provide contract endpoints to the emulator
aleeusgr May 17, 2023
6272217
feat(helios-program.test): copy suggested template and make test pass
aleeusgr May 17, 2023
20d3026
test(tests/helios-program): test properties on api method outputs
aleeusgr May 17, 2023
66fcfd7
style(tests/helios-program): describe it
aleeusgr May 17, 2023
371aa73
refactor(naming-tests): helios.Program, but why this association? in …
aleeusgr May 17, 2023
803e0a3
feat(helios-program-doc.test.ts): added beforeEach to the test
aleeusgr May 18, 2023
b01807c
refactor(/tests-/src): removed non-working code and disabled running …
aleeusgr May 18, 2023
dd9c6cf
feat(tests/helios-vesting): added emulator instantiation with a test …
aleeusgr May 18, 2023
3fcd06f
refactor: deleted old tests to simplify code review process
aleeusgr May 18, 2023
8e50fde
Merge branch 'development' into vesting
aleeusgr May 18, 2023
201fbc6
fix(helios-program-doc.test): changed matching keyhash to vesting to …
aleeusgr May 19, 2023
8f5cc42
Merge branch 'development' into vesting
aleeusgr May 19, 2023
59a5e2d
feat(helios-vesting.test): added Datum
aleeusgr May 19, 2023
1c6dcc8
feat(helios-vesting.test): building the transaction
aleeusgr May 19, 2023
8b5fa1e
feat(helios-vesting.test): completed the tx
aleeusgr May 19, 2023
ed7eee2
style(helios-vestin.test): comments and removing unused parts
aleeusgr May 19, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,67 @@
May 17th, Wednesday

Before I understand, I need to understand what I need to understand
- [ ] a lightweight outline of testable expectations.
- [ ] organization and structure for the testing code.
- [ ] look at testing example in a [production app](https://github.com/Zhengqbbb/cz-git)

My code should be easy to understand.
I use my code as a Lego, having a set of building blocks that work together.

let me write a test for compiling the validator.

May 16th, Tuesday

I have new goal(s); do I? Review README;

May 13th, Saturday

I have to discard three days of work, start anew.
My goal is a loan contract. To build it, I need a testing environemnt to play with.
I have two examples of code that works sending and redeeming tokens from a validator address: vesting in Helios and matching keyhash in lucid.
matching keyhash is simpler, I should start there. Maybe next step would be to rebuild owner-only from Helios in lucid?

May 9th, Tuesday

Feel better, last couple of days were hard;
Merge helios emulator?

May 5, Friday
No wind. Eat, code, sleep, repeat. No life;


May 4, Thursday
Still apathy, but I am pressing forward;
two parts: the contract, and the transactions that serve it, are inseparable; at least for now.
For vesting contract, I have the script, but I need to find transactions; or translate them from the example.
`vesting/pages/index.tsx` imports components in its top,
- [ ] index.tsx: how are components used?
- [ ] loan:

I am pretty exhausted; apathy and sleepiness on Wednesday;
Now my goal is to buid without a manual. So I will start with building with a manual and see where it gets me.

May 2, Tuesday

https://github.com/aleeusgr/potential-robot/issues/70

May 1, Monday

I am unstuck big time; now I have a nicer repo;
9 tests are passing, out of which I know 5;

Now I take a break.

29 Apr, Sat

I am stuck with both refactoring and using Helios nft minter contract to mint an nft in Lucid emulator.
- [ ] look at tutorial Lucid smart contract interaction.

25 April

- [ ] refactor test
- [ ] add nft to borrwer wallet

13 April

rethink
Expand Down
61 changes: 60 additions & 1 deletion README.md
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?
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete 3,4,5


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
104 changes: 104 additions & 0 deletions old-tests/lock-ada.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
// basic.spec.ts
// organizing tests
// https://vitest.dev/api/#test
// `it` is alias for `test`
// test suite;
// test;

import { describe, expect, it, vi } from 'vitest'
import { promises as fs } from 'fs';
import {
Assets,
Address,
ByteArrayData,
ConstrData,
Datum,
ListData,
MintingPolicyHash,
NetworkEmulator,
NetworkParams,
Program,
Value,
textToBytes,
TxOutput,
Tx,
} from "@hyperionbt/helios";

const person = {
isActive: true,
age: 32,
}

let optimize = false;
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 alice = network.createWallet(BigInt(10000000)); // should this be a property?
network.tick(BigInt(10));

describe('state of the emulator', () => {
it('shows that a wallet has been created', () => {
// ahh, ok. Properties;
expect(alice.address).toBeDefined()
})
})
const script = await fs.readFile('./src/owner-only.hl', 'utf8');
const program = Program.new(script);
//space here, maybe I need to modify program using .parameters?
const compiledProgram = program.compile(optimize);

const validatorHash = compiledProgram.validatorHash;
const validatorAddress = Address.fromValidatorHash(validatorHash);

describe('validator properties?', () => {

it('shows that a validator has been created', () => {
// what checks should I can have?
// assert type
// internal checks
expect(person.isActive).toBeTruthy()
})
})
const lock = new Tx()
const ownerPkh = alice.pubKeyHash ;
const datum = new ListData([new ByteArrayData(ownerPkh.bytes),
]);

const inlineDatum = Datum.inline(datum);
const hashedDatum = Datum.hashed(datum);

const lockIn = await network.getUtxos(alice.address)

lock.addInput(lockIn[0]);

const lockTxOutput = new TxOutput(
validatorAddress,
new Value(1000000n), // 1 tAda == 1 million lovelace
inlineDatum
)
lock.addOutput(lockTxOutput)

await lock.finalize(networkParams, alice.address);

const lockTxId = await network.submitTx(lock);
network.tick(BigInt(10));

describe('state of the emulator after the transaction', () => {
it('a utxo at validator address contains correct Datum:', () => {
// const uxto = network.getUtxos();
// tx.dump.body()
//
expect(alice.address).toBeDefined()
})
it('checks validatorAddress', () => {
expect(person.isActive).toBeTruthy()
})

it('is active', () => {
expect(person.isActive).toBeTruthy()
})
it('age limit', () => {
expect(person.age).toBeLessThanOrEqual(32)
})
})
Loading