Skip to content

Commit fd0c1c0

Browse files
authored
Fix for Plutus V3 issues with Lucid Evolution and e2e test (#120)
* fix: Point to yaci-store lucid evo fix branch. Added e2e tests * chore: Meshjs Payment test * chore: PlutusV3 meshjs example
1 parent 3031178 commit fd0c1c0

16 files changed

+453
-1
lines changed

applications/cli/Earthfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ docker-build:
5050
FROM ubuntu:22.04
5151
ENV JAVA_HOME=/opt/java/openjdk
5252
ENV STORE_VERSION=0.1.0
53-
ENV STORE_NATIVE_BRANCH=release/0.2.0-graal-preview1
53+
ENV STORE_NATIVE_BRANCH=release/devkit_lucid_evo
5454

5555
ARG TARGETOS
5656
ARG TARGETARCH

e2e-tests/README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# End-to-End Tests
2+
3+
This folder contains various types of end-to-end tests. Currently, these tests need to be run manually, but automation of the test execution will be implemented in the future.
4+
5+
## Test Categories
6+
7+
1. **api-tests**: This folder contains HTTP API tests, primarily for admin endpoints and essential endpoints from Yaci Store.
8+
2. **lucid-evo**: Compatibility tests for Lucid Evolution.
9+

e2e-tests/api-tests/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
## IntelliJ IDE HTTP Tests
File renamed without changes.

e2e-tests/lucid-evo/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Lucid Evolution Compatibility Tests
2+
3+
## Install Bun
4+
5+
```
6+
curl -fsSL https://bun.sh/install | bash
7+
```
8+
9+
## Run Tests
10+
11+
1. Payment
12+
13+
```shell
14+
bun payment.ts
15+
```
16+
17+
2. Plutus V2 (Always Success)
18+
19+
```shell
20+
bun plutus_v2.ts
21+
```
22+
23+
3. Plutus V3
24+
25+
```shell
26+
bun plutus_v3.ts
27+
```

e2e-tests/lucid-evo/package.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "lucid-evo-example",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"scripts": {
6+
"test": "echo \"Error: no test specified\" && exit 1"
7+
},
8+
"author": "",
9+
"license": "ISC",
10+
"description": "",
11+
"dependencies": {
12+
"@lucid-evolution/lucid": "^0.4.27"
13+
}
14+
}

e2e-tests/lucid-evo/payment.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Lucid, Blockfrost, getAddressDetails } from "@lucid-evolution/lucid";
2+
3+
const lucid = await Lucid(
4+
new Blockfrost("http://localhost:8080/api/v1", "Dummy Key"),
5+
"Custom"
6+
);
7+
8+
const seedPhrase = "test test test test test test test test test test test test test test test test test test test test test test test sauce";
9+
lucid.selectWallet.fromSeed(seedPhrase);
10+
11+
const address = await lucid.wallet().address();
12+
const publicKeyHash = await getAddressDetails(address).paymentCredential.hash;
13+
14+
console.log(address);
15+
16+
const tx = await lucid
17+
.newTx()
18+
.pay.ToAddress("addr_test1qqm87edtdxc7vu2u34dpf9jzzny4qhk3wqezv6ejpx3vgrwt46dz4zq7vqll88fkaxrm4nac0m5cq50jytzlu0hax5xqwlraql",
19+
{ lovelace: 5000000n })
20+
.complete();
21+
22+
const signedTx = await tx.sign.withWallet().complete();
23+
24+
const txHash = await signedTx.submit();
25+
26+
console.log(txHash);

e2e-tests/lucid-evo/plutus_v2.ts

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import { Lucid, Blockfrost, SpendingValidator, validatorToAddress, Data, Constr, getAddressDetails} from "@lucid-evolution/lucid";
2+
3+
const network = "Custom";
4+
5+
const lucid = await Lucid(
6+
new Blockfrost("http://localhost:8080/api/v1", "Dummy Key"),
7+
"Custom"
8+
);
9+
10+
const seedPhrase = "test test test test test test test test test test test test test test test test test test test test test test test sauce";
11+
lucid.selectWallet.fromSeed(seedPhrase);
12+
13+
const address = await lucid.wallet().address();
14+
const publicKeyHash = await getAddressDetails(address).paymentCredential?.hash;
15+
16+
if (!publicKeyHash) throw new Error("Could not get public key hash");
17+
18+
console.log(address);
19+
20+
const spend_val: SpendingValidator = {
21+
type: "PlutusV2",
22+
script: "49480100002221200101"
23+
};
24+
25+
const scriptAddress = validatorToAddress(network, spend_val);
26+
console.log(scriptAddress);
27+
28+
29+
const datum = Data.to(new Constr(0, [publicKeyHash]));
30+
console.log(datum);
31+
32+
const tx = await lucid
33+
.newTx()
34+
.pay.ToContract(scriptAddress, { kind: "inline", value: datum }, { lovelace: 10_000_000n })
35+
.complete();
36+
37+
const signedTx = await tx.sign.withWallet().complete();
38+
const txHash = await signedTx.submit();
39+
40+
console.log(txHash);
41+
42+
//sleep for 10 seconds
43+
await new Promise(resolve => setTimeout(resolve, 3000));
44+
45+
console.log("Spend script UTxO ----");
46+
47+
const DatumSchema = Data.Object({
48+
owner: Data.Bytes(),
49+
});
50+
type DatumType = Data.Static<typeof DatumSchema>;
51+
const DatumType = DatumSchema as unknown as DatumType;
52+
53+
// Find the UTxO we want to spend
54+
const allUTxOs = await lucid.utxosAt(scriptAddress);
55+
const ownerUTxO = allUTxOs.find((utxo) => {
56+
if (utxo.datum) {
57+
const datum = Data.from(utxo.datum, DatumType);
58+
return datum.owner === publicKeyHash;
59+
}
60+
});
61+
62+
if (!ownerUTxO) throw new Error("Could not get utxos");
63+
const redeemer = Data.to(new Constr(0, [Buffer.from("Hello, World!").toString("hex")]));
64+
65+
// Spend script UTxO
66+
const tx2 = await lucid
67+
.newTx()
68+
.collectFrom([ownerUTxO], redeemer)
69+
.attach.SpendingValidator(spend_val)
70+
.complete({
71+
localUPLCEval: false,
72+
});
73+
74+
console.log(tx2.toCBOR());
75+
76+
const signedTx2 = await tx2.sign.withWallet().complete();
77+
78+
console.log("Signed tx2 " + signedTx2.toCBOR());
79+
80+
const txHash2 = await signedTx2.submit();
81+
82+
console.log(txHash2);

e2e-tests/lucid-evo/plutus_v3.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { Lucid, Blockfrost, Kupmios, SpendingValidator, validatorToAddress, Data, Constr, getAddressDetails, OutRef} from "@lucid-evolution/lucid";
2+
3+
const network = "Custom";
4+
5+
const lucid = await Lucid(
6+
new Blockfrost("http://localhost:8080/api/v1", "Dummy Key"),
7+
"Custom"
8+
);
9+
10+
11+
const seedPhrase = "test test test test test test test test test test test test test test test test test test test test test test test sauce";
12+
lucid.selectWallet.fromSeed(seedPhrase);
13+
14+
const address = await lucid.wallet().address();
15+
const publicKeyHash = await getAddressDetails(address).paymentCredential?.hash;
16+
17+
if (!publicKeyHash) throw new Error("Could not get public key hash");
18+
19+
console.log(address);
20+
21+
const spend_val: SpendingValidator = {
22+
type: "PlutusV3",
23+
script: "5857010000323232323225333002323232323253330073370e900118041baa00113232324a26018601a004601600260126ea800458c024c028008c020004c020008c018004c010dd50008a4c26cacae6955ceaab9e5742ae89"
24+
};
25+
26+
const scriptAddress = validatorToAddress(network, spend_val);
27+
console.log(scriptAddress);
28+
29+
const datum = Data.to(new Constr(0, [publicKeyHash]));
30+
31+
const tx = await lucid
32+
.newTx()
33+
.pay.ToContract(scriptAddress, { kind: "inline", value: datum }, { lovelace: 10_000_000n })
34+
.complete();
35+
36+
const signedTx = await tx.sign.withWallet().complete();
37+
38+
const txHash = await signedTx.submit();
39+
40+
console.log(txHash);
41+
42+
await new Promise(resolve => setTimeout(resolve, 3000));
43+
44+
console.log("Spend script UTxO ----");
45+
46+
const DatumSchema = Data.Object({
47+
owner: Data.Bytes(),
48+
});
49+
type DatumType = Data.Static<typeof DatumSchema>;
50+
const DatumType = DatumSchema as unknown as DatumType;
51+
52+
// Find the UTxO we want to spend
53+
const allUTxOs = await lucid.utxosAt(scriptAddress);
54+
const ownerUTxO = allUTxOs.find((utxo) => {
55+
if (utxo.datum) {
56+
const datum = Data.from(utxo.datum, DatumType);
57+
return datum.owner === publicKeyHash;
58+
}
59+
});
60+
61+
if (!ownerUTxO) throw new Error("Could not get utxos");
62+
const redeemer = Data.to(new Constr(0, [Buffer.from("Hello, World!").toString("hex")]));
63+
64+
// Spend script UTxO
65+
const tx2 = await lucid
66+
.newTx()
67+
.collectFrom([ownerUTxO], redeemer) // Provide the redeemer argument
68+
.attach.SpendingValidator(spend_val) // Attach validator
69+
.complete({
70+
localUPLCEval: false,
71+
});
72+
73+
// const evalRes = await provider.evaluateTx(tx2.toCBOR());
74+
75+
console.log(tx2.toCBOR());
76+
77+
const signedTx2 = await tx2.sign.withWallet().complete();
78+
79+
console.log("Signed tx2 ---->>>>>>>>>>>>>>>>>>> " + signedTx2.toCBOR());
80+
81+
const txHash2 = await signedTx2.submit();
82+
83+
console.log(txHash2);

e2e-tests/meshjs/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# MeshJS Compatibility Tests
2+
3+
## Install Bun
4+
5+
```
6+
curl -fsSL https://bun.sh/install | bash
7+
```
8+
9+
## Run Tests
10+
11+
1. Payment
12+
13+
```shell
14+
bun payment.ts
15+
```
16+
17+
2. Payment Splitter (PlutusV3)
18+
19+
```shell
20+
bun payment_splitter_plutusV3.ts
21+
```

e2e-tests/meshjs/package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "meshjs-examples",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"scripts": {
6+
"test": "echo \"Error: no test specified\" && exit 1"
7+
},
8+
"author": "",
9+
"license": "ISC",
10+
"description": "",
11+
"dependencies": {
12+
"@meshsdk/core": "1.9.0-beta-39",
13+
"@meshsdk/core-cst": "1.9.0-beta-39",
14+
"@meshsdk/common": "1.9.0-beta-39"
15+
}
16+
}

e2e-tests/meshjs/payment.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {MeshWallet, Transaction, YaciProvider} from "@meshsdk/core";
2+
3+
const provider = new YaciProvider('http://localhost:8080/api/v1/');
4+
5+
const seedPhrase = ["test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "test", "sauce"];
6+
7+
const wallet = new MeshWallet({
8+
networkId: 0,
9+
fetcher: provider,
10+
submitter: provider,
11+
key: {
12+
type: "mnemonic",
13+
words: seedPhrase,
14+
},
15+
});
16+
17+
const tx = new Transaction({ initiator: wallet });
18+
tx.sendLovelace('addr_test1qrzufj3g0ua489yt235wtc3mrjrlucww2tqdnt7kt5rs09grsag6vxw5v053atks5a6whke03cf2qx3h3g2nhsmzwv3sgml3ed', "2000000");
19+
20+
const unsignedTx = await tx.build();
21+
const signedTx = await wallet.signTx(unsignedTx);
22+
const txHash = await wallet.submitTx(signedTx);
23+
24+
console.log("Tx hash: " + txHash)

0 commit comments

Comments
 (0)