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

Cancel vesting #104

Closed
wants to merge 183 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
183 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
a40fd00
docs(Changelog,-Readme): rfl
aleeusgr May 19, 2023
9d96bf2
style(devlog): created devlog
aleeusgr May 19, 2023
50c3744
docs(devlog): thinking about next step
aleeusgr May 19, 2023
e3d0f22
feat(tests): added test code to explore how test context work
aleeusgr May 19, 2023
35f1916
refactor(helios-vesting.test): added a declaration to vary the durati…
aleeusgr May 20, 2023
c947f0d
feat(lockADA-transaction): Moved transaction building to a separate m…
aleeusgr May 20, 2023
d590428
fix(src/lockAda-and-tests/helios-vesting): fixed the test
aleeusgr May 21, 2023
8caa145
refactor(tests): renamed a test
aleeusgr May 21, 2023
39a051f
feat(helios-vesting.test): added a template
aleeusgr May 21, 2023
d447bfc
feat(helios-vesting-cancel.test): added boilerplate
aleeusgr May 21, 2023
1b0b273
refactor(const-lockAda): changed input to validatorHash instead of va…
aleeusgr May 21, 2023
966c6af
fix(lockAda): broken test
aleeusgr May 21, 2023
0188b1d
feat(cancelVesting): submit lock tx
aleeusgr May 21, 2023
081c434
docs(devlog): rfl
aleeusgr May 21, 2023
bd9f95c
test(lockAda): added nft id
aleeusgr May 21, 2023
59741d1
feat(cancelVesting): added nft mph
aleeusgr May 21, 2023
a527392
feat(tests/helios-vesting-cancel.test): added some more code
aleeusgr May 21, 2023
e22bff4
docs(cancelVesting): rfl
aleeusgr May 22, 2023
4dd978d
feat(cancelVesting): added validFrom and validTo
aleeusgr May 22, 2023
77fea45
feat(cancelVesting): added signer,script and network parameters
aleeusgr May 22, 2023
1a9f2f5
feat(cancelVesting): finalize tx, error
aleeusgr May 22, 2023
bd982e9
fix(cancelVesting): added collateral
aleeusgr May 22, 2023
aa6de3b
test(cancelVesting): transaction contents to screen
aleeusgr May 22, 2023
21f33f0
refactor(tests/helios-vesting-cancel): comments and improve error output
aleeusgr May 22, 2023
0768c5a
fix(test/helios-vesting-cancel): try adding more ada to alice
aleeusgr May 22, 2023
d799586
test(test/helios-vesting-cancel): fixed init test and added a collate…
aleeusgr May 22, 2023
de5166c
refactor(helios-vesting-cancel): get alice utxos with wallet emulator…
aleeusgr May 24, 2023
f8b8d6f
fix(lockAda): tx consumes only one wallet utxo
aleeusgr May 24, 2023
af8f71d
feat(helios-vesting-cancel.test): finalized the transaction
aleeusgr May 24, 2023
ee83e60
feat(cancelVesting): submit tx and tick and query the wallet
aleeusgr May 24, 2023
96dd612
fix(cancelVesting): increased date validTo and more detailed error me…
aleeusgr May 24, 2023
20fb109
fix(cancelVesting): added validTo check
aleeusgr May 25, 2023
b661223
fix(cancelVesting): changed the way time validFrom and validTo calcul…
aleeusgr May 25, 2023
f71149f
test(helios-vesting-cancel-test): moved networkParam init to earlier …
aleeusgr May 26, 2023
98e008b
build(helios): bumped and npm install newer version
aleeusgr May 27, 2023
26725b1
fix(lockAda): added underscores in the main
aleeusgr May 27, 2023
f8b1955
fix(lockAda): fixed minting vesting key
aleeusgr May 27, 2023
3d5cb3c
fix(lockAda.ts): fixed minting vesting nft
aleeusgr May 27, 2023
805ef82
test(helios-vesting-lock.test): expected values changed
aleeusgr May 27, 2023
c68fdd1
merge dev into cancel-vesting
aleeusgr May 27, 2023
8792a16
fix(jelios-vesting-cancel): reproduce last error
aleeusgr May 27, 2023
60051d4
docs(vesting-cancel-test): comments
aleeusgr May 28, 2023
5af9447
docs(devlog): rfl
aleeusgr May 28, 2023
3bfac82
feat(vesting-cancel): added networkParams initialization
aleeusgr May 29, 2023
1abd052
style(vesting-cancel.test): newnp
aleeusgr May 29, 2023
0d39da3
fix(cancelVesting): changed validity range calculation to zero slot
aleeusgr May 30, 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
55 changes: 0 additions & 55 deletions Changelog.md

This file was deleted.

57 changes: 56 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,60 @@
# potential-robot
[source](https://github.com/koralabs/handles-personalization/tree/master/simple_example_wth_tests)

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
149 changes: 149 additions & 0 deletions devlog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
May 28th, Monday

Building cancelAda stalled; I get an error about slot out of range.
I should try with simpler networkParameters, just initial configuration.
I need to build a test for networkParameters

May 21st, Sunday

Huh, coding adventure. Thanks to lley154 I have lockAda;

0: Emulator, Wallets, validator
1: Alice locks 10 Ada for Bob to claim after some time;
1: Alice Cancels
2: Bob Claims
1: Alice fails to cancel
3: Charlie fails to claim.
4: Bob sends Vesting ID to Charlie
2: Change logic:
Alice locks 10 Ada to exchange for a token. Anyone can claim until a Date, but they have to show that the transaction they are submitting has a token attached to it;


Here, I need bob to make difference between Cancel and Claim;


May 19th, Friday

Added tests/helios-vesting.test.ts
However reviewing the code I think: how much redundancy is there already?
Actually, not much. Doc test is ok, just vesting is poorly named; It tests only a small part of the contract functionality; ok, it makes sense to try and factor out a lockAda function that will take enough arguments to submit a successful tx;

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

2 April
Monday reflection lands in this file.
How do I bring Certification and DevX together?
SDLC? What is SDLC?
It's the process more then the result.
"Avoid Success at all costs"

21 March:
Thanks to Randall:
indicating the source-language-agnostic, compiled-and-encoded representation of untyped-plutus-core that is the basis for executing contracts on-chain.

It was done by shell scripting in plutus starter, but now I think Ben suggested I should try
- [ ] `plutus-simple-model`
- [ ] `plutip`

20 March
And now I feel like I am not moving anywhere, or rather that I misunderstood a lot.

I could run psm locally and use `mdbook serve` to get docs
So now I have a front-end component, which is not suited for testing.
I need to find out its identity, the core that makes it tick, which I think is a cborhex file.

This is the file that would be subject to testing. Does it make sense? a dApp is being tested, a category(?) of plutus scripts and their relations.

Tasty, QuickCheck and its analogs.

- [ ] Helios -> cborHex
- [ ] How do we test onchain code?
- [ ] Good tests vs Bad tests - what's the difference?

16 March

The goals starts to be more clear.
I need to run unit tests on desirables.

- [ ] psm
- [ ] helios

then an integration test:

- [ ] psm + helios.

This will allow me to generate and test new logic.
Once I have the logic that I need, I need to search for bugs.
No-code first: use text and graphical descriptions to have a contract model easily accessible.
How do I go on from the model to actual test code?

Enhancements:
- [ ] running CI in the cloud would work around my poor hardware. Tradeoffs?


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