From 6936a53fd37f48955803026256e0bca608fe45bd Mon Sep 17 00:00:00 2001 From: mixmix Date: Tue, 22 Oct 2024 15:38:39 +1300 Subject: [PATCH 1/6] exract "fundAccount" from tests --- tests/account.test.ts | 55 +++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 28 deletions(-) diff --git a/tests/account.test.ts b/tests/account.test.ts index 798451d..70c7078 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,59 @@ 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)) + + // 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('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() From e78b801b683889596ee51d2ead3009754e537824 Mon Sep 17 00:00:00 2001 From: mixmix Date: Tue, 22 Oct 2024 15:52:26 +1300 Subject: [PATCH 2/6] extraaact --- tests/faucet.test.ts | 91 +++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 43 deletions(-) diff --git a/tests/faucet.test.ts b/tests/faucet.test.ts index 1491e15..c35c2b9 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 transfer = new EntropyTransfer(entropy, endpoint) + const account = new EntropyAccount(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: `${20000000000}`, + 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 naynayAccountService = new EntropyAccount(naynay, endpoint) const verifyingKey = await run('register account', naynayAccountService.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 +// }) From ce45b24a111e481b88e9006a10a52347a6934e47 Mon Sep 17 00:00:00 2001 From: mixmix Date: Tue, 22 Oct 2024 16:01:16 +1300 Subject: [PATCH 3/6] tidy --- tests/account.test.ts | 2 -- tests/faucet.test.ts | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/account.test.ts b/tests/account.test.ts index 70c7078..8eec5fa 100644 --- a/tests/account.test.ts +++ b/tests/account.test.ts @@ -95,8 +95,6 @@ test('Account - Register: Default Program', async (t) => { // NOTE: we fund a new account "naynay" because jumpStart has problems with charlie (T_T) await run('fund naynay', fundAccount(t, naynay)) - // 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('jump-start network', jumpStartNetwork(naynay)) const account = new EntropyAccount(naynay, endpoint) diff --git a/tests/faucet.test.ts b/tests/faucet.test.ts index c35c2b9..3c2fa43 100644 --- a/tests/faucet.test.ts +++ b/tests/faucet.test.ts @@ -12,8 +12,8 @@ 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 transfer = new EntropyTransfer(entropy, endpoint) const account = new EntropyAccount(entropy, endpoint) + const transfer = new EntropyTransfer(entropy, endpoint) const faucet = new EntropyFaucet(entropy, endpoint) // Deploy faucet program From c4ecdbd050084e028eb115e32f445bc5f5618a37 Mon Sep 17 00:00:00 2001 From: mix irving Date: Wed, 23 Oct 2024 13:37:36 +1300 Subject: [PATCH 4/6] Update tests/faucet.test.ts Co-authored-by: Nayyir Jutha --- tests/faucet.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/faucet.test.ts b/tests/faucet.test.ts index 3c2fa43..fd8ca70 100644 --- a/tests/faucet.test.ts +++ b/tests/faucet.test.ts @@ -90,7 +90,7 @@ test('Faucet Tests: Successfully send funds and register', async t => { t.equal(naynayBalance, 20000000000, 'Naynay is drippin in faucet tokens') // Test if user can register after receiving funds - const naynayAccountService = new EntropyAccount(naynay, endpoint) + const account = new EntropyAccount(naynay, endpoint) const verifyingKey = await run('register account', naynayAccountService.register()) t.ok(!!verifyingKey, 'Verifying key exists and is returned from register method') From 4378d7f1b8685b38ef953286d4ea5c4387456ac1 Mon Sep 17 00:00:00 2001 From: mix irving Date: Wed, 23 Oct 2024 13:38:02 +1300 Subject: [PATCH 5/6] Update tests/faucet.test.ts Co-authored-by: Nayyir Jutha --- tests/faucet.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/faucet.test.ts b/tests/faucet.test.ts index fd8ca70..bcc1370 100644 --- a/tests/faucet.test.ts +++ b/tests/faucet.test.ts @@ -75,7 +75,7 @@ test('Faucet Tests: Successfully send funds and register', async t => { const transferStatus = await run( 'Sending faucet funds to account', faucet.sendMoney({ - amount: `${20000000000}`, + amount: `${amount}`, addressToSendTo: naynay.keyring.accounts.registration.address, faucetAddress, chosenVerifyingKey, From 332676c5f763ff73d45b189342d50b46f487531e Mon Sep 17 00:00:00 2001 From: Nayyir Jutha Date: Wed, 23 Oct 2024 14:19:17 -0400 Subject: [PATCH 6/6] fixed test --- tests/faucet.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/faucet.test.ts b/tests/faucet.test.ts index bcc1370..e14969c 100644 --- a/tests/faucet.test.ts +++ b/tests/faucet.test.ts @@ -91,7 +91,7 @@ test('Faucet Tests: Successfully send funds and register', async t => { // Test if user can register after receiving funds const account = new EntropyAccount(naynay, endpoint) - const verifyingKey = await run('register account', naynayAccountService.register()) + const verifyingKey = await run('register account', account.register()) t.ok(!!verifyingKey, 'Verifying key exists and is returned from register method')