Skip to content
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

[NayNay] Updating faucet amount #258

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Comment on lines +8 to +11
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💛

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good job writing docs!

// 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💛

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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move this function into dev dir

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do this in a different pr though i'll merge this in now

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 => {
Comment on lines +97 to +98
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this also be an issue?

// 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()
// }
// })
Loading