-
Notifications
You must be signed in to change notification settings - Fork 471
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding in e2e tests for testnet and mainnet
- Loading branch information
Showing
10 changed files
with
175 additions
and
6 deletions.
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
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
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 |
---|---|---|
@@ -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); |
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,12 @@ | ||
{ | ||
"name": "e2e-mainnet", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"start": "node index.js" | ||
}, | ||
"dependencies": { | ||
"@provablehq/sdk": "^0.6.0" | ||
} | ||
} |
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,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); |
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,12 @@ | ||
{ | ||
"name": "e2e-testnet", | ||
"private": true, | ||
"version": "0.0.0", | ||
"type": "module", | ||
"scripts": { | ||
"start": "node index.js" | ||
}, | ||
"dependencies": { | ||
"@provablehq/sdk": "^0.6.0" | ||
} | ||
} |
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