Use mintedTotallyByBridge for bridge-ui statistics (#135)
* Use mintedTotallyByBridge for bridge-ui statistics
This commit is contained in:
parent
4e5e21541e
commit
319b493568
@ -19,7 +19,10 @@ import {
|
||||
ZERO_ADDRESS,
|
||||
getDeployedAtBlock,
|
||||
getValidatorList,
|
||||
getTokenType
|
||||
getTokenType,
|
||||
getValidatorContract,
|
||||
getRequiredSignatures,
|
||||
getValidatorCount
|
||||
} from './utils/contract'
|
||||
import { balanceLoaded, removePendingTransaction } from './utils/testUtils'
|
||||
import sleep from './utils/sleep'
|
||||
@ -390,16 +393,14 @@ class ForeignStore {
|
||||
@action
|
||||
async getValidators() {
|
||||
try {
|
||||
const foreignValidatorsAddress = await this.foreignBridge.methods.validatorContract().call()
|
||||
const foreignValidatorsAddress = await getValidatorContract(this.foreignBridge)
|
||||
this.foreignBridgeValidators = new this.foreignWeb3.eth.Contract(
|
||||
BRIDGE_VALIDATORS_ABI,
|
||||
foreignValidatorsAddress
|
||||
)
|
||||
|
||||
this.requiredSignatures = await this.foreignBridgeValidators.methods
|
||||
.requiredSignatures()
|
||||
.call()
|
||||
this.validatorsCount = await this.foreignBridgeValidators.methods.validatorCount().call()
|
||||
this.requiredSignatures = await getRequiredSignatures(this.foreignBridgeValidators)
|
||||
this.validatorsCount = await getValidatorCount(this.foreignBridgeValidators)
|
||||
|
||||
this.validators = await getValidatorList(foreignValidatorsAddress, this.foreignWeb3.eth)
|
||||
} catch (e) {
|
||||
|
@ -15,7 +15,7 @@ import {
|
||||
getDecimals,
|
||||
getTotalSupply,
|
||||
getBalanceOf,
|
||||
mintedTotally,
|
||||
mintedTotallyByBridge,
|
||||
totalBurntCoins,
|
||||
getName,
|
||||
getFeeManager,
|
||||
@ -24,7 +24,11 @@ import {
|
||||
getFeeManagerMode,
|
||||
ZERO_ADDRESS,
|
||||
getValidatorList,
|
||||
getDeployedAtBlock
|
||||
getDeployedAtBlock,
|
||||
getBlockRewardContract,
|
||||
getValidatorContract,
|
||||
getRequiredSignatures,
|
||||
getValidatorCount
|
||||
} from './utils/contract'
|
||||
import { balanceLoaded, removePendingTransaction } from './utils/testUtils'
|
||||
import sleep from './utils/sleep'
|
||||
@ -253,7 +257,10 @@ class HomeStore {
|
||||
balanceLoaded()
|
||||
})
|
||||
} else if (this.rootStore.bridgeMode === BRIDGE_MODES.ERC_TO_NATIVE) {
|
||||
const mintedCoins = await mintedTotally(this.blockRewardContract)
|
||||
const mintedCoins = await mintedTotallyByBridge(
|
||||
this.blockRewardContract,
|
||||
this.HOME_BRIDGE_ADDRESS
|
||||
)
|
||||
const burntCoins = await totalBurntCoins(this.homeBridge)
|
||||
this.balance = fromDecimals(mintedCoins.minus(burntCoins).toString(10), this.tokenDecimals)
|
||||
} else {
|
||||
@ -418,14 +425,14 @@ class HomeStore {
|
||||
@action
|
||||
async getValidators() {
|
||||
try {
|
||||
const homeValidatorsAddress = await this.homeBridge.methods.validatorContract().call()
|
||||
const homeValidatorsAddress = await getValidatorContract(this.homeBridge)
|
||||
this.homeBridgeValidators = new this.homeWeb3.eth.Contract(
|
||||
BRIDGE_VALIDATORS_ABI,
|
||||
homeValidatorsAddress
|
||||
)
|
||||
|
||||
this.requiredSignatures = await this.homeBridgeValidators.methods.requiredSignatures().call()
|
||||
this.validatorsCount = await this.homeBridgeValidators.methods.validatorCount().call()
|
||||
this.requiredSignatures = await getRequiredSignatures(this.homeBridgeValidators)
|
||||
this.validatorsCount = await getValidatorCount(this.homeBridgeValidators)
|
||||
|
||||
this.validators = await getValidatorList(homeValidatorsAddress, this.homeWeb3.eth)
|
||||
} catch (e) {
|
||||
@ -524,7 +531,7 @@ class HomeStore {
|
||||
}
|
||||
|
||||
async getBlockRewardContract() {
|
||||
const blockRewardAddress = await this.homeBridge.methods.blockRewardContract().call()
|
||||
const blockRewardAddress = await getBlockRewardContract(this.homeBridge)
|
||||
this.blockRewardContract = new this.homeWeb3.eth.Contract(BLOCK_REWARD_ABI, blockRewardAddress)
|
||||
}
|
||||
|
||||
|
55
ui/src/stores/__tests__/HomeStore.test.js
Normal file
55
ui/src/stores/__tests__/HomeStore.test.js
Normal file
@ -0,0 +1,55 @@
|
||||
import Web3 from 'web3'
|
||||
import BN from 'bignumber.js'
|
||||
import HomeStore from '../HomeStore'
|
||||
import { BRIDGE_MODES } from '../utils/bridgeMode'
|
||||
import * as contract from '../utils/contract'
|
||||
import * as web3StoreUtils from '../utils/web3'
|
||||
|
||||
describe('HomeStore', () => {
|
||||
const rootStore = {
|
||||
web3Store: {
|
||||
injectedWeb3: new Web3(),
|
||||
homeWeb3: new Web3()
|
||||
},
|
||||
foreignStore: {
|
||||
feeEventsFinished: true,
|
||||
feeManager: {}
|
||||
},
|
||||
bridgeModeInitialized: true,
|
||||
bridgeMode: BRIDGE_MODES.ERC_TO_NATIVE
|
||||
}
|
||||
it('should call mintedTotallyByBridge', async () => {
|
||||
// Method to spy
|
||||
contract.mintedTotallyByBridge = jest.fn(() => Promise.resolve(new BN(100)))
|
||||
|
||||
// Other mocks
|
||||
contract.totalBurntCoins = jest.fn(() => Promise.resolve(new BN(0)))
|
||||
contract.getBlockRewardContract = jest.fn(() =>
|
||||
Promise.resolve('0xCecBE80Ed3548dE11D7d2D922a36576eA40C4c26')
|
||||
)
|
||||
contract.getPastEvents = jest.fn(() => Promise.resolve([]))
|
||||
web3StoreUtils.getBlockNumber = jest.fn(() => Promise.resolve(10))
|
||||
contract.getMinPerTxLimit = jest.fn(() => Promise.resolve(100000000))
|
||||
contract.getMaxPerTxLimit = jest.fn(() => Promise.resolve(10000000000))
|
||||
contract.getCurrentLimit = jest.fn(() => Promise.resolve({}))
|
||||
contract.getValidatorContract = jest.fn(() =>
|
||||
Promise.resolve('0xcDF12C376F43A70a07d7Ad2fD3449634717C9235')
|
||||
)
|
||||
contract.getRequiredSignatures = jest.fn(() => Promise.resolve(1))
|
||||
contract.getValidatorCount = jest.fn(() => Promise.resolve(1))
|
||||
contract.getValidatorList = jest.fn(() =>
|
||||
Promise.resolve(['0x52576e0cCaA0C9157142Fbf1d1c6DbfAc5e4E33e'])
|
||||
)
|
||||
|
||||
// When
|
||||
new HomeStore(rootStore)
|
||||
|
||||
// Need to wait until HomeStore is initialized
|
||||
await new Promise(resolve => {
|
||||
setTimeout(() => {
|
||||
expect(contract.mintedTotallyByBridge).toHaveBeenCalled()
|
||||
resolve()
|
||||
}, 1000)
|
||||
})
|
||||
})
|
||||
})
|
@ -1,4 +1,5 @@
|
||||
import { getTokenType } from '../contract'
|
||||
import BN from 'bignumber.js'
|
||||
import { getTokenType, mintedTotallyByBridge } from '../contract'
|
||||
import { ERC_TYPES } from '../bridgeMode'
|
||||
|
||||
describe('getTokenType', () => {
|
||||
@ -60,3 +61,26 @@ describe('getTokenType', () => {
|
||||
expect(type).toEqual(ERC_TYPES.ERC20)
|
||||
})
|
||||
})
|
||||
describe('mintedTotallyByBridge', () => {
|
||||
it('should call mintedTotallyByBridge from contract', async () => {
|
||||
// Given
|
||||
const bridgeAddress = '0xCecBE80Ed3548dE11D7d2D922a36576eA40C4c26'
|
||||
const value = '120000'
|
||||
const contract = {
|
||||
methods: {
|
||||
mintedTotallyByBridge: address => {
|
||||
return {
|
||||
call: () => Promise.resolve(address === bridgeAddress ? value : '0')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// When
|
||||
const result = await mintedTotallyByBridge(contract, bridgeAddress)
|
||||
|
||||
// Then
|
||||
expect(BN.isBigNumber(result)).toBeTruthy()
|
||||
expect(result.toString()).toEqual(value)
|
||||
})
|
||||
})
|
||||
|
@ -53,8 +53,8 @@ export const getBalanceOf = async (contract, address) => {
|
||||
return fromDecimals(balance, decimals)
|
||||
}
|
||||
|
||||
export const mintedTotally = async contract => {
|
||||
const mintedCoins = await contract.methods.mintedTotally().call()
|
||||
export const mintedTotallyByBridge = async (contract, bridgeAddress) => {
|
||||
const mintedCoins = await contract.methods.mintedTotallyByBridge(bridgeAddress).call()
|
||||
return new BN(mintedCoins)
|
||||
}
|
||||
|
||||
@ -170,3 +170,11 @@ export const getTokenType = async (contract, bridgeAddress) => {
|
||||
return ERC_TYPES.ERC20
|
||||
}
|
||||
}
|
||||
|
||||
export const getBlockRewardContract = contract => contract.methods.blockRewardContract().call()
|
||||
|
||||
export const getValidatorContract = contract => contract.methods.validatorContract().call()
|
||||
|
||||
export const getRequiredSignatures = contract => contract.methods.requiredSignatures().call()
|
||||
|
||||
export const getValidatorCount = contract => contract.methods.validatorCount().call()
|
||||
|
Loading…
Reference in New Issue
Block a user