Skip to content

Instantly share code, notes, and snippets.

@tinchoabbate
Created April 5, 2019 21:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tinchoabbate/0b9f01ae08a3acc13938a36edb1e0632 to your computer and use it in GitHub Desktop.
Save tinchoabbate/0b9f01ae08a3acc13938a36edb1e0632 to your computer and use it in GitHub Desktop.
BeamBalanceStore keeps 13 generations instead of 12
/* eslint-env mocha */
/* global artifacts, assert, describe, web3, require, context, beforeEach, it */
/* global contract */
const chai = require('chai');
const { BN } = web3.utils;
const bnChai = require('bn-chai');
const { expect } = chai;
const PolicyInit = artifacts.require('PolicyInit');
const ForwardProxy = artifacts.require('ForwardProxy');
const FakePolicy = artifacts.require('FakePolicy');
const FakeInflation = artifacts.require('FakeInflation');
const MurderousPolicy = artifacts.require('MurderousPolicy');
const BeamBalanceStore = artifacts.require('BeamBalanceStore');
const UNKNOWN_POLICY_ID = web3.utils.soliditySha3('AttemptedMurder');
const util = require('../../tools/test/util.js');
chai.use(bnChai(BN));
contract('BeamBalanceStore', (accounts) => {
let balanceStore;
let policy;
let murderer;
let attemptedMurderer;
let inflationPolicy;
const [creator] = accounts;
beforeEach('global setup', async () => {
const policyInit = await PolicyInit.new();
const proxy = await ForwardProxy.new(policyInit.address);
balanceStore = await BeamBalanceStore.new(proxy.address, { from: creator });
murderer = await MurderousPolicy.new();
attemptedMurderer = await MurderousPolicy.new();
inflationPolicy = await FakeInflation.new();
const policyIdentifiers = [
await balanceStore.ID_CLEANUP(),
UNKNOWN_POLICY_ID,
await balanceStore.ID_INFLATION(),
];
await (await PolicyInit.at(proxy.address)).fusedInit(
(await FakePolicy.new()).address,
policyIdentifiers,
policyIdentifiers,
[murderer.address, attemptedMurderer.address, inflationPolicy.address],
[],
);
policy = await FakePolicy.at(proxy.address);
});
describe('Generations', () => {
context('for a stale account', () => {
const [, testAccount] = accounts;
const accountBalance = 1000;
beforeEach(async () => {
await inflationPolicy.mint(balanceStore.address, testAccount, accountBalance);
originalGeneration = (await balanceStore.generation()).toNumber();
await util.increaseTime(31557600 / 10, accounts[0]);
await balanceStore.incrementGeneration();
});
it.only('ZEPPELIN - contract keeps 13 generations instead of 12', async () => {
let currentGeneration = await balanceStore.generation();
// Advance to generation 13
for (let index = 0; index < 13 - currentGeneration; index++) {
await util.increaseTime(31557600 / 10);
await balanceStore.incrementGeneration();
}
// Contract is in generation 13
currentGeneration = await balanceStore.generation();
expect(currentGeneration).to.eq.BN(13);
// Account is not in generation 13
expect(await balanceStore.isUpdated(testAccount)).to.be.false;
await balanceStore.updateTo(testAccount, currentGeneration);
// Account is now in generation 13 too
expect(await balanceStore.isUpdated(testAccount)).to.be.true;
// Contract is keeping 13 generations of the account's balance instead of 12
for (let generation = 1; generation <= 13; generation++) {
expect(
await balanceStore.balanceAt(testAccount, generation)
).to.eq.BN(accountBalance);
}
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment