Skip to content

Commit

Permalink
refactor: added verified Admin address and check test
Browse files Browse the repository at this point in the history
  • Loading branch information
StanislavShevchenko committed Jan 23, 2020
1 parent 1ad3e83 commit 36b93b2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .env.dev
Expand Up @@ -29,6 +29,6 @@ FUSE_API=https://explorer.fuse.io
TWILIO_AUTH_ID=
TWILIO_AUTH_TOKEN=
TWILIO_PHONE_NUMBER=
NUMBER_OF_ADMIN_WALLET_ACCOUNTS=10
NUMBER_OF_ADMIN_WALLET_ACCOUNTS=1
ADMIN_MIN_BALANCE=100000
MARKET_PASSWORD=markettokenmarkettokenmarkettoke
39 changes: 23 additions & 16 deletions src/server/blockchain/AdminWallet.js
Expand Up @@ -129,12 +129,17 @@ export class Wallet {
this.network = conf.network
this.networkId = conf.ethereum.network_id

this.proxyContract = new this.web3.eth.Contract(
ProxyContractABI.abi,
get(ContractsAddress, `${this.network}.AdminWallet`)
)

txManager.getTransactionCount = this.web3.eth.getTransactionCount
await txManager.createListIfNotExists(this.addresses)
for (let addr of this.addresses) {
const balance = await this.web3.eth.getBalance(addr)
log.info(`admin wallet ${addr} balance ${balance}`)
if (balance > adminMinBalance) {
if ((await this.isVerifiedAdmin(addr)) && balance > adminMinBalance) {
log.info(`admin wallet ${addr} balance ${balance}`)
this.filledAddresses.push(addr)
}
}
Expand All @@ -150,12 +155,6 @@ export class Wallet {
{ from: this.address }
)

this.proxyContract = new this.web3.eth.Contract(
ProxyContractABI.abi,
get(ContractsAddress, `${this.network}.AdminWallet`),
{ from: this.address }
)

this.signUpBonusContract = new this.web3.eth.Contract(
SignUpBonusABI.abi,
get(ContractsAddress, `${this.network}.SignupBonus`),
Expand Down Expand Up @@ -184,14 +183,6 @@ export class Wallet {
nonce: this.nonce,
ContractsAddress: ContractsAddress[this.network]
})
await this.removeWhitelisted('0x6ddfF36dE47671BF9a2ad96438e518DD633A0e63').catch(_ => _)
const whitelistTest = await this.whitelistUser('0x6ddfF36dE47671BF9a2ad96438e518DD633A0e63', 'x')
const topwalletTest = await this.topWallet(
'0x6ddfF36dE47671BF9a2ad96438e518DD633A0e63',
moment().subtract(1, 'day'),
true
)
log.info('wallet tests:', { whitelist: whitelistTest.status, topwallet: topwalletTest.status })
} catch (e) {
log.error('Error initializing wallet', { e, errMessage: e.message })
if (conf.env !== 'test') process.exit(-1)
Expand Down Expand Up @@ -364,6 +355,22 @@ export class Wallet {
return tx
}

/**
*
* @param {string} address
* @returns {Promise<boolean>}
*/
async isVerifiedAdmin(address: string): Promise<boolean> {
const tx: boolean = await this.proxyContract.methods
.isAdmin(address)
.call()
.catch(e => {
log.error('Error isAdmin', { e, errMessage: e.message })
throw e
})
return tx
}

/**
* top wallet if needed
* @param {string} address
Expand Down
7 changes: 2 additions & 5 deletions src/server/blockchain/__tests__/adminWallet.test.js
Expand Up @@ -48,7 +48,7 @@ describe('adminwallet', () => {
const promises = []
for (let i = 0; i < 5; i++) {
const unverifiedAddress = generateWalletAddress()
const tx = await AdminWallet.whitelistUser(unverifiedAddress, 'did:gd')
// console.log('unverifiedAddress', unverifiedAddress)
promises.push(AdminWallet.topWallet(unverifiedAddress, null, true))
}
const res = await Promise.all(promises).catch(_ => false)
Expand All @@ -57,14 +57,12 @@ describe('adminwallet', () => {

test('adminWallet bad transaction in queue', async () => {
const unverifiedAddress = generateWalletAddress()
const unverifiedAddress2 = generateWalletAddress()
const from = AdminWallet.address
const testValue = 10
const badGas = 10
let tx

//good tx
await AdminWallet.whitelistUser(unverifiedAddress, 'did:gd')
tx = await AdminWallet.topWallet(unverifiedAddress, null, true)
expect(tx).toBeTruthy()

Expand All @@ -80,8 +78,7 @@ describe('adminwallet', () => {
).rejects.toThrow()

//good tx
await AdminWallet.whitelistUser(unverifiedAddress2, 'did:gd')
tx = await AdminWallet.topWallet(unverifiedAddress2, null, true)
tx = await AdminWallet.topWallet(unverifiedAddress, null, true)
expect(tx).toBeTruthy()
})

Expand Down

0 comments on commit 36b93b2

Please sign in to comment.