Smart contracts for the Besu permissioning system
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
permissioning-smart-contracts/test/test-account-rules-read-onl...

75 lines
2.3 KiB

const Ingress = artifacts.require('AccountIngress.sol');
const Rules = artifacts.require('AccountRules.sol');
const Admin = artifacts.require('Admin.sol');
var address1 = "0xdE3422671D38EcdD7A75702Db7f54d4b30C022Ea".toLowerCase();
contract('Account Rules (Read-only mode)', () => {
let ingressContract;
let adminContract;
let rulesContract;
beforeEach(async () => {
ingressContract = await Ingress.deployed();
rulesContract = await Rules.new(Ingress.address);
})
it("should toggle read-only flag on enter/exit read-mode method invocation", async () => {
let readOnly = await rulesContract.isReadOnly();
assert.notOk(readOnly);
await rulesContract.enterReadOnly();
readOnly = await rulesContract.isReadOnly();
assert.ok(readOnly);
await rulesContract.exitReadOnly();
readOnly = await rulesContract.isReadOnly();
assert.notOk(readOnly);
});
it("should fail when adding account in read-only mode", async () => {
await rulesContract.enterReadOnly();
try {
await rulesContract.addAccount(address1);
assert.fail("Expected error when adding on readOnly mode");
} catch (err) {
expect(err.reason).to.contain("In read only mode: rules cannot be modified");
}
});
it("should fail when removing account in read-only mode", async () => {
await rulesContract.enterReadOnly();
try {
await rulesContract.removeAccount(address1);
assert.fail("Expected error when adding on readOnly mode");
} catch (err) {
expect(err.reason).to.contain("In read only mode: rules cannot be modified");
}
});
it("should fail when attempting to exit read-only mode and contract is not in read-only mode", async () => {
try {
await rulesContract.exitReadOnly();
assert.fail("Expected error when exiting read-only mode not being in read-only mode");
} catch (err) {
expect(err.reason).to.contain("Not in read only mode");
}
});
it("should fail when attempting to enter read-only mode and contract is alread in read-only mode", async () => {
await rulesContract.enterReadOnly();
try {
await rulesContract.enterReadOnly();
assert.fail("Expected error when entering read-only mode being in read-only mode");
} catch (err) {
expect(err.reason).to.contain("Already in read only mode");
}
});
});