Skip to content

Commit

Permalink
[NayNay] Updating faucet amount (#258)
Browse files Browse the repository at this point in the history
* udpated tests, wrote new test to test failed route for register but running into an issue with tape possibly, commented test out for now

* removing unnecessary reset
  • Loading branch information
rh0delta authored Oct 18, 2024
1 parent 5f3960b commit ee2709b
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 21 deletions.
5 changes: 4 additions & 1 deletion src/faucet/interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { EntropyFaucet } from "./main"
import { print } from "src/common/utils"

let chosenVerifyingKeys = []
const amount = "10000000000"
// Sending only 1e10 BITS does not allow user's to register after receiving funds
// there are limits in place to ensure user's are leftover with a certain balance in their accounts
// increasing amount send here, will allow user's to register right away
const amount = "20000000000"
// context for logging file
const FLOW_CONTEXT = 'ENTROPY_FAUCET_INTERACTION'
export async function entropyFaucet (entropy: Entropy, options, logger: EntropyLogger) {
Expand Down
1 change: 1 addition & 0 deletions src/faucet/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export const FAUCET_PROGRAM_MOD_KEY = '5GWamxgW4XWcwGsrUynqnFq2oNZPqNXQhMDfgNH9x
// this is differnt from tests because the fauce that is live now was lazily deployed without schemas
// TO-DO: update this when faucet is deployed properly
export const TESTNET_PROGRAM_HASH = '0x12af0bd1f2d91f12e34aeb07ea622c315dbc3c2bdc1e25ff98c23f1e61106c77'
// Hash with max send of 1e10
export const LOCAL_PROGRAM_HASH = '0x5fa0536818acaa380b0c349c8e887bf269d593a47e30c8e31de53a75d327f7b1'
93 changes: 73 additions & 20 deletions tests/faucet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,18 @@ import { EntropyFaucet } from '../src/faucet/main'
import { LOCAL_PROGRAM_HASH } from '../src/faucet/utils'
import { EntropyAccount } from '../src/account/main'

test('Faucet Tests', async t => {
async function setupAndFundFaucet (t, naynayEntropy) {
const { run, entropy, endpoint } = await setupTest(t, { seed: charlieStashSeed })
const { entropy: naynayEntropy } = await setupTest(t)

const balanceService = new EntropyBalance(entropy, endpoint)
const accountService = new EntropyAccount(entropy, endpoint)
const transferService = new EntropyTransfer(entropy, endpoint)
const faucetService = new EntropyFaucet(naynayEntropy, endpoint)
const accountService = new EntropyAccount(entropy, endpoint)

const faucetProgram = readFileSync('tests/programs/faucet_program.wasm')

const genesisHash = await entropy.substrate.rpc.chain.getBlockHash(0)

const userConfig = {
max_transfer_amount: 10_000_000_000,
max_transfer_amount: 20_000_000_000,
genesis_hash: stripHexPrefix(genesisHash.toString())
}
const configurationSchema = {
Expand All @@ -41,11 +38,7 @@ test('Faucet Tests', async t => {

// Confirm faucetPointer matches deployed program pointer
t.equal(faucetProgramPointer, LOCAL_PROGRAM_HASH, 'Program pointer matches')
let entropyBalance = await balanceService.getBalance(entropy.keyring.accounts.registration.address)
console.log('Balance Charlie::', entropyBalance);

let naynayBalance = await balanceService.getBalance(naynayEntropy.keyring.accounts.registration.address)
t.equal(naynayBalance, 0, 'Naynay is broke af')

// register with faucet program
await run('Register Faucet Program for charlie stash', accountService.register(
{
Expand All @@ -57,29 +50,89 @@ test('Faucet Tests', async t => {
// @ts-expect-error
const { chosenVerifyingKey, faucetAddress } = faucetService.getRandomFaucet([], verifyingKeys)
// adding funds to faucet address
entropyBalance = await balanceService.getBalance(entropy.keyring.accounts.registration.address)
const faucetAddressBalance = await balanceService.getBalance(faucetAddress)
console.log('Balance faucetAddress::', faucetAddressBalance);
console.log('Balance charlie 2::', entropyBalance);


await run('Transfer funds to faucet address', transferService.transfer(faucetAddress, "1000"))

const transferStatus = await faucetService.sendMoney(
return { faucetProgramPointer, chosenVerifyingKey, faucetAddress }
}

test('Faucet Tests: Successfully send funds and register', async t => {
const { run, endpoint, entropy: naynayEntropy } = await setupTest(t)

const faucetService = new EntropyFaucet(naynayEntropy, endpoint)
const balanceService = new EntropyBalance(naynayEntropy, endpoint)

const { faucetAddress, chosenVerifyingKey, faucetProgramPointer } = await setupAndFundFaucet(t, naynayEntropy)

let naynayBalance = await balanceService.getBalance(naynayEntropy.keyring.accounts.registration.address)
t.equal(naynayBalance, 0, 'Naynay is broke af')

const transferStatus = await run('Sending faucet funds to account', faucetService.sendMoney(
{
amount: "10000000000",
amount: "20000000000",
addressToSendTo: naynayEntropy.keyring.accounts.registration.address,
faucetAddress,
chosenVerifyingKey,
faucetProgramPointer
}
)
))

t.ok(transferStatus.isFinalized, 'Transfer is good')

naynayBalance = await balanceService.getBalance(naynayEntropy.keyring.accounts.registration.address)

t.ok(naynayBalance > 0, '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())

t.ok(!!verifyingKey, 'Verifying key exists and is returned from register method')

const fullAccount = naynayEntropy.keyring.getAccount()
t.equal(verifyingKey, fullAccount?.registration?.verifyingKeys?.[0], 'verifying key matches key added to registration account')

t.end()
})

// TODO: @naynay fix below test for register failing when only sending 1e10 bits
// test('Faucet Tests: Successfully send funds but cannot register', async t => {
// const { run, endpoint, entropy: naynayEntropy } = await setupTest(t)

// const faucetService = new EntropyFaucet(naynayEntropy, endpoint)
// const balanceService = new EntropyBalance(naynayEntropy, endpoint)

// const { faucetAddress, chosenVerifyingKey, faucetProgramPointer } = await setupAndFundFaucet(t, naynayEntropy)

// let naynayBalance = await balanceService.getBalance(naynayEntropy.keyring.accounts.registration.address)
// t.equal(naynayBalance, 0, 'Naynay is broke af')

// const transferStatus = await run('Sending faucet funds to account', faucetService.sendMoney(
// {
// amount: "10000000000",
// addressToSendTo: naynayEntropy.keyring.accounts.registration.address,
// faucetAddress,
// chosenVerifyingKey,
// faucetProgramPointer
// }
// ))

// t.ok(transferStatus.isFinalized, 'Transfer is good')

// naynayBalance = await balanceService.getBalance(naynayEntropy.keyring.accounts.registration.address)

// t.ok(naynayBalance > 0, 'Naynay is drippin in faucet tokens')

// // Test if user can register after receiving funds
// const naynayAccountService = new EntropyAccount(naynayEntropy, endpoint)
// try {
// const verifyingKey = await naynayAccountService.register()
// console.log('ver key', verifyingKey);

// // t.fail('Register should fail')
// } catch (error) {
// console.log('error', error);

// t.pass('Regsitration failed')
// t.end()
// }
// })

0 comments on commit ee2709b

Please sign in to comment.