-
Notifications
You must be signed in to change notification settings - Fork 0
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
Mixmix/programs deploy #206
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
688e8de
merge user/dev programs flows
mixmix 93e0ae2
ts fixups
mixmix 56260a0
import fixups in test (remove baseUrl dependence)
mixmix 21cb32c
test programs deploy
mixmix f4e6814
plug it innnn
mixmix 8e524bb
Merge branch 'dev' of github.com:entropyxyz/cli into mixmix/programs_…
mixmix 21c142d
Update tests/programs.test.ts
mixmix 222071e
CHANGELOG
mixmix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import Entropy from "@entropyxyz/sdk"; | ||
import fs from "node:fs/promises" | ||
import { isAbsolute, join } from "node:path" | ||
import { u8aToHex } from "@polkadot/util" | ||
|
||
import { DeployProgramParams } from "./types" | ||
|
||
export async function deployProgram (entropy: Entropy, params: DeployProgramParams) { | ||
const bytecode = await loadFile(params.bytecodePath) | ||
const configurationSchema = await loadFile(params.configurationSchemaPath, 'json') | ||
const auxillaryDataSchema = await loadFile(params.auxillaryDataSchemaPath, 'json') | ||
// QUESTION: where / how are schema validated? | ||
|
||
return entropy.programs.dev.deploy( | ||
bytecode, | ||
jsonToHex(configurationSchema), | ||
jsonToHex(auxillaryDataSchema) | ||
) | ||
} | ||
|
||
function loadFile (path?: string, encoding?: string) { | ||
if (path === undefined) return | ||
|
||
const absolutePath = isAbsolute(path) | ||
? path | ||
: join(process.cwd(), path) | ||
|
||
switch (encoding) { | ||
case undefined: | ||
return fs.readFile(absolutePath) | ||
|
||
case 'json': | ||
return fs.readFile(absolutePath, 'utf-8') | ||
.then(string => JSON.parse(string)) | ||
|
||
default: | ||
throw Error('unknown encoding: ' + encoding) | ||
// return fs.readFile(absolutePath, encoding) | ||
} | ||
} | ||
|
||
function jsonToHex (obj?: object) { | ||
if (obj === undefined) return | ||
|
||
const encoder = new TextEncoder() | ||
const byteArray = encoder.encode(JSON.stringify(obj)) | ||
|
||
return u8aToHex(new Uint8Array(byteArray)) | ||
} |
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 |
---|---|---|
@@ -1,57 +1,77 @@ | ||
import test from 'tape' | ||
import { readFileSync } from 'node:fs' | ||
|
||
import { promiseRunner, charlieStashSeed, setupTest } from './testing-utils' | ||
import { addProgram } from '../src/flows/programs/add' | ||
import { viewPrograms } from '../src/flows/programs/view' | ||
import { removeProgram } from '../src/flows/programs/remove' | ||
import { AddProgramParams } from '../src/flows/programs/types' | ||
import { deployProgram } from '../src/flows/programs/deploy' | ||
|
||
const networkType = 'two-nodes' | ||
|
||
test('programs', async t => { | ||
const { run, entropy } = await setupTest(t, { seed: charlieStashSeed, networkType }) | ||
await run('charlie stash register', entropy.register()) | ||
const noopProgram: any = readFileSync( | ||
new URL('./programs/program_noop.wasm', import.meta.url) | ||
) | ||
const newPointer = await run( | ||
'deploy', | ||
entropy.programs.dev.deploy(noopProgram) | ||
) | ||
|
||
const noopProgramInstance: AddProgramParams = { | ||
programPointer: newPointer, | ||
programConfig: '', | ||
} | ||
|
||
t.test('Add Program', async ap => { | ||
const runAp = promiseRunner(ap) | ||
|
||
const programsBeforeAdd = await runAp('get programs initial', entropy.programs.get(entropy.programs.verifyingKey)) | ||
ap.equal(programsBeforeAdd.length, 1, 'charlie has 1 program') | ||
await runAp('adding program', addProgram(entropy, noopProgramInstance)) | ||
const programsAfterAdd = await runAp('get programs after add', entropy.programs.get(entropy.programs.verifyingKey)) | ||
ap.equal(programsAfterAdd.length, 2, 'charlie has 2 programs') | ||
ap.end() | ||
await run('register', entropy.register()) // TODO: consider removing this in favour of just testing add | ||
|
||
let programPointer1 | ||
|
||
t.test('programs - deploy', async t => { | ||
const run = promiseRunner(t) | ||
|
||
programPointer1 = await run ( | ||
'deploy!', | ||
deployProgram(entropy, { | ||
bytecodePath: './tests/programs/program_noop.wasm' | ||
}) | ||
) | ||
|
||
t.end() | ||
}) | ||
|
||
t.test('Remove Program', async rp => { | ||
const runRp = promiseRunner(rp) | ||
const programsBeforeRemove = await runRp('get programs initial', entropy.programs.get(entropy.programs.verifyingKey)) | ||
|
||
rp.equal(programsBeforeRemove.length, 2, 'charlie has 2 programs') | ||
await runRp('removing noop program', removeProgram(entropy, { programPointer: newPointer, verifyingKey: entropy.programs.verifyingKey })) | ||
const programsAfterRemove = await runRp('get programs initial', entropy.programs.get(entropy.programs.verifyingKey)) | ||
rp.equal(programsAfterRemove.length, 1, 'charlie has 1 less program') | ||
rp.end() | ||
const getPrograms = () => viewPrograms(entropy, { verifyingKey: entropy.programs.verifyingKey }) | ||
const verifyingKey = entropy.programs.verifyingKey | ||
|
||
t.test('programs - add', async t => { | ||
const run = promiseRunner(t) | ||
|
||
const programsBeforeAdd = await run('get programs initial', getPrograms()) | ||
t.equal(programsBeforeAdd.length, 1, 'charlie has 1 program') | ||
|
||
await run( | ||
'adding program', | ||
addProgram(entropy, { programPointer: programPointer1, programConfig: '' }) | ||
) | ||
const programsAfterAdd = await run('get programs after add', getPrograms()) | ||
t.equal(programsAfterAdd.length, 2, 'charlie has 2 programs') | ||
|
||
t.end() | ||
}) | ||
|
||
t.test('View Program', async vp => { | ||
const runVp = promiseRunner(vp) | ||
const programs = await runVp('get charlie programs', viewPrograms(entropy, { verifyingKey: entropy.programs.verifyingKey })) | ||
t.test('programs - remove', async t => { | ||
const run = promiseRunner(t) | ||
|
||
const programsBeforeRemove = await run('get programs initial', getPrograms()) | ||
t.equal(programsBeforeRemove.length, 2, 'charlie has 2 programs') | ||
|
||
await run( | ||
'removing noop program', | ||
removeProgram(entropy, { programPointer: programPointer1, verifyingKey }) | ||
) | ||
const programsAfterRemove = await run('get programs initial', getPrograms()) | ||
t.equal(programsAfterRemove.length, 1, 'charlie has 1 less program') | ||
|
||
t.end() | ||
}) | ||
|
||
t.test('programs - view', async t => { | ||
const run = promiseRunner(t) | ||
|
||
const programs = await run( | ||
'get charlie programs', | ||
viewPrograms(entropy, { verifyingKey }) | ||
) | ||
|
||
t.equal(programs.length, 1, 'charlie has 1 program') | ||
|
||
vp.equal(programs.length, 1, 'charlie has 1 program') | ||
vp.end() | ||
t.end() | ||
}) | ||
}) |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies I moved lines around. Essentially
t
andrun
("know your scope" is sufficient?)[action, query?, assertionOfChange, '\n']