Skip to content

Commit

Permalink
Adds initialized to checkVariables; consolidates check of initialized…
Browse files Browse the repository at this point in the history
… into single function
  • Loading branch information
o-a-hudson committed Aug 7, 2018
1 parent 09c208e commit bf7c142
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
12 changes: 5 additions & 7 deletions test/MiscTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var masterMinterAccount = tokenUtils.masterMinterAccount;
var minterAccount = tokenUtils.minterAccount;
var pauserAccount = tokenUtils.pauserAccount;
var initializeTokenWithProxy = tokenUtils.initializeTokenWithProxy;
var getInitializedV1 = tokenUtils.getInitializedV1;
var FiatToken = tokenUtils.FiatToken;

var amount = 100;
Expand Down Expand Up @@ -438,19 +439,16 @@ async function run_tests(newToken) {
});

it('ms045 initialized should be in slot 8, byte 21', async function() {
var slot8Data = await web3.eth.getStorageAt(proxy.address, 8);
var initialized = "0x" + slot8Data.substring(2,4); // first 2 hex-chars after 0x
var masterMinterAddress = "0x" + slot8Data.substring(4,44); // first 42 hex chars after 0xii

assert.equal(masterMinterAccount, masterMinterAddress);
var initialized = await getInitializedV1(token);
assert.equal("0x01", initialized);
});

it('ms046 initialized should be 0 before initialization', async function() {
var rawToken = await newToken();
var newProxy = await FiatTokenProxy.new(rawToken.address, { from: arbitraryAccount });
var slot8Data = await web3.eth.getStorageAt(newProxy.address, 8);
assert.equal("0x00", slot8Data);
var token = FiatToken.at(newProxy.address);
var initialized = await getInitializedV1(token);
assert.equal("0x00", initialized);
});

}
Expand Down
34 changes: 34 additions & 0 deletions test/TokenTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var symbol = 'C-USD';
var currency = 'USD';
var decimals = 2;
var BigNumber = require('bignumber.js');
var trueInStorageFormat = "0x01";
var bigZero = new BigNumber(0);
var bigHundred = new BigNumber(100);
var assertDiff = require('assert-diff');
Expand Down Expand Up @@ -204,6 +205,7 @@ function buildExpectedState(token, customVars) {
'blacklister': blacklisterAccount,
'tokenOwner': tokenOwnerAccount,
'proxiedTokenAddress': token.proxiedTokenAddress,
'initializedV1': trueInStorageFormat,
'upgrader': proxyOwnerAccount,
'balances': {
'arbitraryAccount': bigZero,
Expand Down Expand Up @@ -372,6 +374,7 @@ async function getActualState(token) {
await token.owner.call(),
await getImplementation(token),
await getAdmin(token),
await getInitializedV1(token),
await token.balanceOf(arbitraryAccount),
await token.balanceOf(masterMinterAccount),
await token.balanceOf(minterAccount),
Expand Down Expand Up @@ -462,6 +465,7 @@ async function getActualState(token) {
tokenOwner,
proxiedTokenAddress,
upgrader,
initializedV1,
balancesA,
balancesMM,
balancesM,
Expand Down Expand Up @@ -553,6 +557,7 @@ async function getActualState(token) {
'tokenOwner': tokenOwner,
'proxiedTokenAddress': proxiedTokenAddress,
'upgrader': upgrader,
'initializedV1': initializedV1,
'balances': {
'arbitraryAccount': balancesA,
'masterMinterAccount': balancesMM,
Expand Down Expand Up @@ -884,6 +889,34 @@ function getImplementation(proxy) {
return impl;
}

async function getInitializedV1(token) {
var slot8Data = await web3.eth.getStorageAt(token.address, 8);
var slot8DataLength = slot8Data.length;
var initialized;
var masterMinterStart;
var masterMinterAddress;
if (slot8DataLength == 4) {
//Validate proxy not yet initialized
for (var i = 0; i <= 20; i++) {
assert.equal("0x00", await web3.eth.getStorageAt(token.address, i));
}
initialized = slot8Data;
} else {
if (slot8DataLength == 44) {
initialized = "0x" + slot8Data.substring(2,4); // first 2 hex-chars after 0x
masterMinterStart = 4;
} else if (slot8DataLength == 40) {
initialized = "0x00";
masterMinterStart = 2;
} else {
assert.fail("slot8Data incorrect size");
}
masterMinterAddress = "0x" + slot8Data.substring(masterMinterStart, masterMinterStart + 40);
assert.equal(await token.masterMinter.call(), masterMinterAddress);
}
return initialized;
}

module.exports = {
FiatToken: FiatToken,
FiatTokenProxy: FiatTokenProxy,
Expand Down Expand Up @@ -937,6 +970,7 @@ module.exports = {
expectRevert: expectRevert,
expectJump: expectJump,
encodeCall: encodeCall,
getInitializedV1: getInitializedV1,
deployerAccount: deployerAccount,
arbitraryAccount: arbitraryAccount,
tokenOwnerAccount: tokenOwnerAccount,
Expand Down

0 comments on commit bf7c142

Please sign in to comment.