-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ISSUE#405 dev programs rework (#409)
<!-- Provide a brief description of the changes made in this PR --> ## Related Issue(s) <!-- Link to the issue(s) that this PR addresses --> closes #405 ## Testing <!-- Describe how you tested the changes --> - [x] Unit tests added/updated - [x] Integration tests added/updated ## Checklist <!-- Confirm that the following items are true and correct: --> - [x] I have performed a self-review of my code. - [ ] I have commented my code. - [ ] I have updated documentation, where necessary.
- Loading branch information
Showing
7 changed files
with
231 additions
and
50 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import test from 'tape' | ||
import { readFileSync } from 'fs' | ||
import Entropy, { wasmGlobalsReady } from '../src' | ||
import Keyring from '../src/keys' | ||
|
||
import { | ||
promiseRunner, | ||
spinNetworkUp, | ||
charlieStashAddress, | ||
spinNetworkDown, | ||
createTestAccount, | ||
} from './testing-utils' | ||
|
||
const networkType = 'two-nodes' | ||
|
||
test('Programs#dev: all methods', async (t) => { | ||
const run = promiseRunner(t) | ||
await run('network up', spinNetworkUp(networkType)) | ||
|
||
await run('wasm', wasmGlobalsReady()) | ||
|
||
const entropy = await createTestAccount() | ||
|
||
t.teardown(async () => { | ||
await entropy.close() | ||
await spinNetworkDown(networkType) | ||
}) | ||
|
||
|
||
// wait for entropy to be ready | ||
await run( | ||
'entropy ready', | ||
entropy.ready | ||
) | ||
|
||
|
||
// deploy | ||
const noopProgram: any = readFileSync( | ||
'./tests/testing-utils/program_noop.wasm', | ||
|
||
) | ||
|
||
const configSchema = { | ||
type: 'object', | ||
properties: { | ||
noop_param: { type: 'string' } | ||
} | ||
} | ||
const auxDataSchema = { | ||
type: 'object', | ||
properties: { | ||
noop_param: { type: 'number' } | ||
} | ||
} | ||
const newPointer = await run( | ||
'deploy', | ||
entropy.programs.dev.deploy(noopProgram, configSchema, auxDataSchema) | ||
) | ||
console.log('newPointer:', newPointer) | ||
const programsDeployed = await run( | ||
'get deployed programs', | ||
entropy.programs.dev.getByDeployer(entropy.keyring.accounts.programDev.address) | ||
) | ||
t.deepEqual( | ||
programsDeployed, | ||
[newPointer], | ||
'charlie has 1 program deployed' | ||
) | ||
|
||
// Helpful error for old usage | ||
try { | ||
await entropy.programs.dev.get(entropy.keyring.accounts.programDev.address) | ||
t.fail('entropy.programs.dev.get(entropy.keyring.accounts.programDev.address) should have failed') | ||
} catch (e) { | ||
t.ok(e.message.includes('pointer length is less then or equal to 48. are you using an address?'), 'should error when using an address') | ||
} | ||
|
||
const noopProgramOnChain = await run( | ||
'get a specific program', | ||
entropy.programs.dev.get(newPointer) | ||
) | ||
|
||
t.deepEqual( | ||
noopProgramOnChain.bytecode, | ||
noopProgram, | ||
'bytecode on chain should match what was deployed' | ||
) | ||
t.deepEqual( | ||
noopProgramOnChain.configurationSchema, | ||
configSchema, | ||
'configurationSchema on chain should match what was deployed' | ||
) | ||
t.deepEqual( | ||
noopProgramOnChain.auxiliaryDataSchema, | ||
auxDataSchema, | ||
'auxiliaryDataSchema on chain should match what was deployed' | ||
) | ||
|
||
run( | ||
'remove noopProgram', | ||
entropy.programs.dev.remove(newPointer) | ||
) | ||
|
||
const programsDeployedAfterRemove = await run( | ||
'get deployed programs', | ||
entropy.programs.dev.getByDeployer(entropy.keyring.accounts.programDev.address) | ||
) | ||
// the removal of a program has failed | ||
// the removing of a program is questionable | ||
// functionality to begin with so ive commented this out | ||
// for now but this needs digging | ||
// see issue https://github.com/entropyxyz/sdk/issues/414 | ||
// t.equal( | ||
// programsDeployedAfterRemove.length, | ||
// 0, | ||
// 'charlie has no deployed programs' | ||
// ) | ||
|
||
|
||
t.end() | ||
}) |
Oops, something went wrong.