Skip to content

Commit b35c91c

Browse files
committed
Update pricing-test.js to use separate statistics contract
1 parent 8e6e62e commit b35c91c

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

solidity/scripts/pricing-test.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const KeepRandomBeaconServiceImplV1 = artifacts.require("KeepRandomBeaconServiceImplV1.sol");
22
const KeepRandomBeaconService = artifacts.require('KeepRandomBeaconService.sol');
33
const KeepRandomBeaconOperator = artifacts.require('KeepRandomBeaconOperator.sol');
4+
const KeepRandomBeaconOperatorStatistics = artifacts.require('KeepRandomBeaconOperatorStatistics.sol');
45
const fs = require('fs');
56

67
// MAKE SURE NONE OF THOSE ACCOUNTS IS A MINER ACCOUNT
@@ -20,6 +21,7 @@ module.exports = async function() {
2021
const keepRandomBeaconService = await KeepRandomBeaconService.deployed();
2122
const contractService = await KeepRandomBeaconServiceImplV1.at(keepRandomBeaconService.address);
2223
const contractOperator = await KeepRandomBeaconOperator.deployed();
24+
const contractStatistics = await KeepRandomBeaconOperatorStatistics.deployed();
2325

2426
let accounts = operators.slice();
2527
accounts.push(requestor);
@@ -39,7 +41,7 @@ module.exports = async function() {
3941

4042
for (let i = 0; i < accounts.length; i++) {
4143
prevBalances[i] = await web3.eth.getBalance(accounts[i]);
42-
prevRewards[i] = (await availableRewards(accounts[i], contractOperator)).toString();
44+
prevRewards[i] = (await availableRewards(accounts[i], contractOperator, contractStatistics)).toString();
4345
}
4446

4547
let gasPrice = await web3.eth.getGasPrice();
@@ -79,7 +81,7 @@ module.exports = async function() {
7981
const balance = await web3.eth.getBalance(address);
8082
const balanceChange = web3.utils.toBN(balance).sub(web3.utils.toBN(prevBalances[i])).toString();
8183

82-
const reward = (await availableRewards(address, contractOperator)).toString();
84+
const reward = (await availableRewards(address, contractOperator, contractStatistics)).toString();
8385
const rewardChange = web3.utils.toBN(reward).sub(web3.utils.toBN(prevRewards[i])).toString();
8486

8587
const pricingClient = new PricingClient(
@@ -110,7 +112,7 @@ module.exports = async function() {
110112
}
111113
};
112114

113-
async function availableRewards(account, contractOperator) {
115+
async function availableRewards(account, contractOperator, contractStatistics) {
114116
const expiredGroupCount = (await contractOperator.getFirstActiveGroupIndex()).toNumber();
115117
const activeGroupCount = (await contractOperator.numberOfGroups()).toNumber();
116118
const totalGroupCount = expiredGroupCount + activeGroupCount;
@@ -122,9 +124,9 @@ async function availableRewards(account, contractOperator) {
122124

123125
let accountRewards = web3.utils.toBN(0);
124126
for (let i = 0; i < groupsPublicKeys.length; i++) {
125-
const groupMembersCount = (await contractOperator.getGroupMemberIndices(groupsPublicKeys[i], account)).length;
127+
const groupMembersCount = await contractStatistics.countGroupMembership(groupsPublicKeys[i], account);
126128
const groupMemberReward = await contractOperator.getGroupMemberRewards(groupsPublicKeys[i]);
127-
accountRewards = accountRewards.add(web3.utils.toBN(groupMembersCount).mul(groupMemberReward));
129+
accountRewards = accountRewards.add(groupMembersCount.mul(groupMemberReward));
128130
}
129131

130132
return accountRewards;
@@ -170,4 +172,4 @@ PricingClient.prototype.toString = function pricingClientToString() {
170172

171173
function wait(ms) {
172174
return new Promise(resolve => setTimeout(resolve, ms));
173-
}
175+
}

0 commit comments

Comments
 (0)