I have two contracts that both inherit from OpenZeppelin's Whitelist. After deploying both contracts, I use an instance of the first contract to add a "trusted" address to the whitelist. Since both contracts inherit from the same Whitelist, I would assume that the second contract also sees that "trusted" is whitelisted. However, I don't see that when running tests. My questions are below the code.
contracts A and B:
pragma solidity ^0.4.23;
import "openzeppelin-solidity/contracts/ownership/Whitelist.sol";
contract A is Whitelist {
}
contract B is Whitelist {
}
migration 2_deploy.js:
var A = artifacts.require("./A.sol");
var B = artifacts.require("./B.sol");
module.exports = function(deployer, network, accounts) {
var owner = accounts[0];
var trusted = accounts[1];
deployer.deploy(A, {from: owner})
.then(function(){
console.log("A deployed");
return;
});
deployer.deploy(B, {from: owner})
.then(function(){
console.log("B deployed");
return;
});
A.deployed()
.then(function(instance) {
instance.addAddressToWhitelist(trusted, {from: owner})
.then(function() {
return;
});
});
};
test.js:
const A = artifacts.require("A");
const B = artifacts.require("B");
contract('A', async (accounts) => {
let owner = accounts[0];
let trusted = accounts[1];
a = await A.deployed();
b = await B.deployed();
let isWhitelistedA = await a.whitelist(trusted);
let isWhitelistedB = await b.whitelist(trusted);
console.log("before adding trusted, contract A: "+isWhitelistedA);
console.log("before adding trusted, contract B: "+isWhitelistedB);
await a.addAddressToWhitelist(trusted, {from: owner});
isWhitelistedA = await a.whitelist(trusted);
isWhitelistedB = await b.whitelist(trusted);
console.log("after adding trusted to A, contract A: "+isWhitelistedA);
console.log("after adding trusted to A, contract B: "+isWhitelistedB);
await b.addAddressToWhitelist(trusted, {from: owner});
isWhitelistedA = await a.whitelist(trusted);
isWhitelistedB = await b.whitelist(trusted);
console.log("after adding trusted to B, contract A: "+isWhitelistedA);
console.log("after adding trusted to B, contract B: "+isWhitelistedB);
})
truffle test output:
before adding trusted, contract A: false
before adding trusted, contract B: false
after adding trusted to A, contract A: true
after adding trusted to A, contract B: false
after adding trusted to B, contract A: true
after adding trusted to B, contract B: true
Questions:
- Why trusted is not whitelisted before being added in the Test? Migration should have added it.
- When trusted is whitelisted via A's instance, why is it not whitelisted according to B? Inheritance should have taken care of that.
Notes:
- This might be me not understanding how "deployed" and instances work, so please enlighten me what is happening :).
- test.js is obviously not a proper Truffle Test (as nothing is really tested), but it is a reduced example of a problem I am facing.
Other info:
- Truffle v4.1.8 (core: 4.1.8)
- Solidity v0.4.23 (solc-js)
- using Ganache with localhost