Skip to content

Commit

Permalink
Adding in e2e tests for testnet and mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
Pauan committed Aug 6, 2024
1 parent c634f69 commit a2bdf48
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 6 deletions.
25 changes: 25 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,25 @@ jobs:
yarn test
e2e-testnet:
executor: rust-node
steps:
- setup-sdk
- run:
working_directory: e2e/testnet
command: |
yarn start
e2e-mainnet:
executor: rust-node
steps:
- setup-sdk
- run:
working_directory: e2e/mainnet
command: |
yarn start
template-node:
executor: rust-node
steps:
Expand Down Expand Up @@ -145,6 +164,12 @@ workflows:
- sdk-test:
requires:
- sdk
- e2e-testnet:
requires:
- sdk
- e2e-mainnet:
requires:
- sdk
- template-node:
requires:
- sdk
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/staging-website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly-2024-05-14
toolchain: nightly-2024-07-21
override: true
components: rustfmt, rust-src

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test-website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly-2024-05-14
toolchain: nightly-2024-07-21
override: true
components: rustfmt, rust-src

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly-2024-05-14
toolchain: nightly-2024-07-21
override: true
components: rustfmt, rust-src

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"wasm",
"website",
"create-leo-app",
"create-leo-app/*"
"create-leo-app/*",
"e2e",
"e2e/*"
],
"type": "module",
"scripts": {
Expand Down
59 changes: 59 additions & 0 deletions sdk/e2e/mainnet/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import {Account, initThreadPool, ProgramManager, AleoKeyProvider, AleoKeyProviderParams} from "@provablehq/sdk/mainnet.js";

await initThreadPool();

const programName = "hello_hello.aleo"

const hello_hello_program =`
program ${programName};
function hello:
input r0 as u32.public;
input r1 as u32.private;
add r0 r1 into r2;
output r2 as u32.private;`

async function localProgramExecution(program, programName, aleoFunction, inputs) {
const programManager = new ProgramManager();

// Create a temporary account for the execution of the program
const account = new Account();
programManager.setAccount(account);

// Create a key provider in order to re-use the same key for each execution
const keyProvider = new AleoKeyProvider();
keyProvider.useCache(true);
programManager.setKeyProvider(keyProvider);

// Pre-synthesize the program keys and then cache them in memory using key provider
const keyPair = await programManager.synthesizeKeys(hello_hello_program, aleoFunction, inputs);
programManager.keyProvider.cacheKeys(`${programName}:${aleoFunction}`, keyPair);

// Specify parameters for the key provider to use search for program keys. In particular specify the cache key
// that was used to cache the keys in the previous step.
const keyProviderParams = new AleoKeyProviderParams({cacheKey: `${programName}:${aleoFunction}`});

// Execute once using the key provider params defined above. This will use the cached proving keys and make
// execution significantly faster.
let executionResponse = await programManager.run(
program,
aleoFunction,
inputs,
true,
undefined,
keyProviderParams,
);
console.log("hello_hello/hello executed - result:", executionResponse.getOutputs());

// Verify the execution using the verifying key that was generated earlier.
if (programManager.verifyExecution(executionResponse)) {
console.log("hello_hello/hello execution verified!");
} else {
throw("Execution failed verification!");
}
}

const start = Date.now();
console.log("Starting execute!");
await localProgramExecution(hello_hello_program, programName, "hello", ["5u32", "5u32"]);
console.log("Execute finished!", Date.now() - start);
12 changes: 12 additions & 0 deletions sdk/e2e/mainnet/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "e2e-mainnet",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"@provablehq/sdk": "^0.6.0"
}
}
59 changes: 59 additions & 0 deletions sdk/e2e/testnet/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import {Account, initThreadPool, ProgramManager, AleoKeyProvider, AleoKeyProviderParams} from "@provablehq/sdk/testnet.js";

await initThreadPool();

const programName = "hello_hello.aleo"

const hello_hello_program =`
program ${programName};
function hello:
input r0 as u32.public;
input r1 as u32.private;
add r0 r1 into r2;
output r2 as u32.private;`

async function localProgramExecution(program, programName, aleoFunction, inputs) {
const programManager = new ProgramManager();

// Create a temporary account for the execution of the program
const account = new Account();
programManager.setAccount(account);

// Create a key provider in order to re-use the same key for each execution
const keyProvider = new AleoKeyProvider();
keyProvider.useCache(true);
programManager.setKeyProvider(keyProvider);

// Pre-synthesize the program keys and then cache them in memory using key provider
const keyPair = await programManager.synthesizeKeys(hello_hello_program, aleoFunction, inputs);
programManager.keyProvider.cacheKeys(`${programName}:${aleoFunction}`, keyPair);

// Specify parameters for the key provider to use search for program keys. In particular specify the cache key
// that was used to cache the keys in the previous step.
const keyProviderParams = new AleoKeyProviderParams({cacheKey: `${programName}:${aleoFunction}`});

// Execute once using the key provider params defined above. This will use the cached proving keys and make
// execution significantly faster.
let executionResponse = await programManager.run(
program,
aleoFunction,
inputs,
true,
undefined,
keyProviderParams,
);
console.log("hello_hello/hello executed - result:", executionResponse.getOutputs());

// Verify the execution using the verifying key that was generated earlier.
if (programManager.verifyExecution(executionResponse)) {
console.log("hello_hello/hello execution verified!");
} else {
throw("Execution failed verification!");
}
}

const start = Date.now();
console.log("Starting execute!");
await localProgramExecution(hello_hello_program, programName, "hello", ["5u32", "5u32"]);
console.log("Execute finished!", Date.now() - start);
12 changes: 12 additions & 0 deletions sdk/e2e/testnet/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "e2e-testnet",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"@provablehq/sdk": "^0.6.0"
}
}
4 changes: 2 additions & 2 deletions website/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ This project was bootstrapped with [Vite](https://vitejs.dev/).
- Install [wasm-pack](https://rustwasm.github.io/wasm-pack/installer/)

```bash
rustup toolchain install nightly-2023-05-24
rustup component add rust-src --toolchain nightly-2023-05-24
rustup toolchain install nightly-2024-07-21
rustup component add rust-src --toolchain nightly-2024-07-21
yarn
yarn dev
```
Expand Down

0 comments on commit a2bdf48

Please sign in to comment.