-
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/new sdk rc #263
Mixmix/new sdk rc #263
Changes from 2 commits
6936a53
e78b801
ce45b24
c4ecdbd
4378d7f
b47d526
332676c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. less words means less reading. I'm pretty happy we're not gonna get collisions and am watching closely for that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the rest of this file, I shuffled lines around such that there are groupings like
This is fully an opinionated style thing, but it makes reading quicker because the relevant context is grouped into parcels. 🤷 |
||
|
||
// 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}`, | ||
mixmix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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') | ||
mixmix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Test if user can register after receiving funds | ||
const naynayAccountService = new EntropyAccount(naynayEntropy, endpoint) | ||
const naynayAccountService = new EntropyAccount(naynay, endpoint) | ||
mixmix marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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() | ||
// } | ||
// }) | ||
// }) |
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.
I loved the pattern you started extracting some other setup. I noticed that we want a funded account which is just "set up" for us and that extracting it made the tests a whole lot simpler (to my mind any way)