diff --git a/tests/account.test.ts b/tests/account.test.ts index 798451d..8eec5fa 100644 --- a/tests/account.test.ts +++ b/tests/account.test.ts @@ -1,5 +1,5 @@ import test from 'tape' -import { wasmGlobalsReady } from '@entropyxyz/sdk' +import { Entropy, wasmGlobalsReady } from '@entropyxyz/sdk' // @ts-ignore import { isValidSubstrateAddress } from '@entropyxyz/sdk/utils' import { jumpStartNetwork } from '@entropyxyz/sdk/testing' @@ -80,60 +80,57 @@ test('Account - import', async t => { t.end() }) -const networkType = 'four-nodes' const endpoint = 'ws://127.0.0.1:9944' +async function fundAccount (t, entropy: Entropy) { + const { entropy: charlie } = await setupTest(t, { seed: charlieStashSeed }) + const transfer = new EntropyTransfer(charlie, endpoint) + + await transfer.transfer(entropy.keyring.accounts.registration.address, "1000") +} + + test('Account - Register: Default Program', async (t) => { - const { run, entropy } = await setupTest(t, { networkType, seed: charlieStashSeed }) - // Naynay entropy instance required here as @JesseAbram brought to attn that running jumpstart using the charlie seed will result in errors. - // the error found here was: RpcError: 1014: Priority is too low: (4471 vs 4471): The transaction has too low priority to replace another transaction already in the pool. - // which indicated a potential nonce issue, where the solution would be to manually wait for ~50 blocks to make any subsequent calls to the network. However, - // using naynay instance (fresh seed) jump start and the subsequent calls to the network (i.e register), the flow worked without issues. - const { entropy: naynay } = await setupTest(t, { networkType }) - - const accountService = new EntropyAccount(naynay, endpoint) - const transferService = new EntropyTransfer(entropy, endpoint) - - // use of charlie seed is solely to transfer funds to the naynay (fresh seed) instance. these funds will be used for the jumpstart and register call - await run('transferring funds', transferService.transfer(naynay.keyring.accounts.registration.address, "1000")) + const { run, entropy: naynay } = await setupTest(t) + // NOTE: we fund a new account "naynay" because jumpStart has problems with charlie (T_T) + await run('fund naynay', fundAccount(t, naynay)) + await run('jump-start network', jumpStartNetwork(naynay)) - const verifyingKey = await run('register account', accountService.register()) + const account = new EntropyAccount(naynay, endpoint) + const verifyingKey = await run('register account', account.register()) const fullAccount = naynay.keyring.getAccount() - t.equal(verifyingKey, fullAccount?.registration?.verifyingKeys?.[0], 'verifying key matches key added to registration account') t.end() }) test('Account - Register: Barebones Program', async t => { - const { run, entropy } = await setupTest(t, { networkType, seed: eveSeed }) - const { entropy: naynay } = await setupTest(t, { networkType }) - // await run('jump-start network', jumpStartNetwork(entropy)) + const { run, entropy: naynay } = await setupTest(t) + await run('fund naynay', fundAccount(t, naynay)) + // NOTE: we fund a new account "naynay" because jumpStart has problems with charlie (T_T) + const dummyProgram: any = readFileSync( new URL('./programs/template_barebones.wasm', import.meta.url) ) - const accountService = new EntropyAccount(naynay, endpoint) - const transferService = new EntropyTransfer(entropy, endpoint) - - await run('transferring funds', transferService.transfer(naynay.keyring.accounts.registration.address, "1000")) await run('jump-start network', jumpStartNetwork(naynay)) + + const account = new EntropyAccount(naynay, endpoint) const pointer = await run( 'deploy program', - entropy.programs.dev.deploy(dummyProgram) + naynay.programs.dev.deploy(dummyProgram) ) const verifyingKey = await run( - 'register - using custom params', - accountService.register({ - programModAddress: entropy.keyring.accounts.registration.address, + 'register account - with custom params', + account.register({ + programModAddress: naynay.keyring.accounts.registration.address, programData: [{ program_pointer: pointer, program_config: '0x' }], }) ) const fullAccount = naynay.keyring.getAccount() - t.equal(verifyingKey, fullAccount?.registration?.verifyingKeys?.[0], 'verifying key matches key added to registration account') t.end() diff --git a/tests/faucet.test.ts b/tests/faucet.test.ts index 1491e15..e14969c 100644 --- a/tests/faucet.test.ts +++ b/tests/faucet.test.ts @@ -12,18 +12,12 @@ import { EntropyAccount } from '../src/account/main' async function setupAndFundFaucet (t) { const { run, entropy, endpoint } = await setupTest(t, { seed: eveSeed }) await run('jump-start network', jumpStartNetwork(entropy)) - const accountService = new EntropyAccount(entropy, endpoint) - const transferService = new EntropyTransfer(entropy, endpoint) - const faucetService = new EntropyFaucet(entropy, endpoint) + const account = new EntropyAccount(entropy, endpoint) + const transfer = new EntropyTransfer(entropy, endpoint) + const faucet = new EntropyFaucet(entropy, endpoint) + // Deploy faucet program const faucetProgram = readFileSync('tests/programs/faucet_program.wasm') - - const genesisHash = await entropy.substrate.rpc.chain.getBlockHash(0) - - const userConfig = { - max_transfer_amount: 20_000_000_000, - genesis_hash: stripHexPrefix(genesisHash.toString()) - } const configurationSchema = { max_transfer_amount: "number", genesis_hash: "string" @@ -34,63 +28,74 @@ async function setupAndFundFaucet (t) { spec_version: "number", transaction_version: "number", } - - // Deploy faucet program - const faucetProgramPointer = await run('Deploy faucet program', entropy.programs.dev.deploy(faucetProgram, configurationSchema, auxDataSchema)) - - // Confirm faucetPointer matches deployed program pointer + const faucetProgramPointer = await run( + 'Deploy faucet program', + entropy.programs.dev.deploy(faucetProgram, configurationSchema, auxDataSchema) + ) t.equal(faucetProgramPointer, LOCAL_PROGRAM_HASH, 'Program pointer matches') - // register with faucet program - await run('Register Faucet Program for eve', accountService.register( - { + // Register with faucet program + const genesisHash = await entropy.substrate.rpc.chain.getBlockHash(0) + const userConfig = { + max_transfer_amount: 20_000_000_000, + genesis_hash: stripHexPrefix(genesisHash.toString()) + } + await run( + 'Register Faucet Program for eve', + account.register({ programModAddress: entropy.keyring.accounts.registration.address, - programData: [{ program_pointer: faucetProgramPointer, program_config: userConfig }] - } - )) - const verifyingKeys = await faucetService.getAllFaucetVerifyingKeys(entropy.keyring.accounts.registration.address) + programData: [{ + program_pointer: + faucetProgramPointer, + program_config: userConfig + }] + }) + ) + + // Fund the Faucet + const verifyingKeys = await faucet.getAllFaucetVerifyingKeys(entropy.keyring.accounts.registration.address) // @ts-expect-error - const { chosenVerifyingKey, faucetAddress } = faucetService.getRandomFaucet([], verifyingKeys) - // adding funds to faucet address - await run('Transfer funds to faucet address', transferService.transfer(faucetAddress, "1000")) + const { chosenVerifyingKey, faucetAddress } = faucet.getRandomFaucet([], verifyingKeys) + await run('Transfer funds to faucet address', transfer.transfer(faucetAddress, "1000")) return { faucetProgramPointer, chosenVerifyingKey, faucetAddress } } test('Faucet Tests: Successfully send funds and register', async t => { - const { run, endpoint, entropy: naynayEntropy } = await setupTest(t) + const { run, endpoint, entropy: naynay } = await setupTest(t) + const { faucetAddress, chosenVerifyingKey, faucetProgramPointer } = await setupAndFundFaucet(t) - const faucetService = new EntropyFaucet(naynayEntropy, endpoint) - const balanceService = new EntropyBalance(naynayEntropy, endpoint) + const faucet = new EntropyFaucet(naynay, endpoint) + const balance = new EntropyBalance(naynay, endpoint) - const { faucetAddress, chosenVerifyingKey, faucetProgramPointer } = await setupAndFundFaucet(t) - - let naynayBalance = await balanceService.getBalance(naynayEntropy.keyring.accounts.registration.address) + let naynayBalance = await balance.getBalance(naynay.keyring.accounts.registration.address) t.equal(naynayBalance, 0, 'Naynay is broke af') - - const transferStatus = await run('Sending faucet funds to account', faucetService.sendMoney( - { - amount: "20000000000", - addressToSendTo: naynayEntropy.keyring.accounts.registration.address, + + const amount = 20000000000 + const transferStatus = await run( + 'Sending faucet funds to account', + faucet.sendMoney({ + amount: `${amount}`, + addressToSendTo: naynay.keyring.accounts.registration.address, faucetAddress, chosenVerifyingKey, faucetProgramPointer - } - )) + }) + ) t.ok(transferStatus.isFinalized, 'Transfer is good') - naynayBalance = await balanceService.getBalance(naynayEntropy.keyring.accounts.registration.address) + naynayBalance = await balance.getBalance(naynay.keyring.accounts.registration.address) - t.ok(naynayBalance > 0, 'Naynay is drippin in faucet tokens') + t.equal(naynayBalance, 20000000000, 'Naynay is drippin in faucet tokens') // Test if user can register after receiving funds - const naynayAccountService = new EntropyAccount(naynayEntropy, endpoint) - const verifyingKey = await run('register account', naynayAccountService.register()) + const account = new EntropyAccount(naynay, endpoint) + const verifyingKey = await run('register account', account.register()) t.ok(!!verifyingKey, 'Verifying key exists and is returned from register method') - const fullAccount = naynayEntropy.keyring.getAccount() + const fullAccount = naynay.keyring.getAccount() t.equal(verifyingKey, fullAccount?.registration?.verifyingKeys?.[0], 'verifying key matches key added to registration account') t.end() @@ -137,4 +142,4 @@ test('Faucet Tests: Successfully send funds and register', async t => { // t.pass('Regsitration failed') // t.end() // } -// }) \ No newline at end of file +// })