-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathupgradeable.js
71 lines (56 loc) · 2.99 KB
/
upgradeable.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
var Dispatcher = artifacts.require("./upgradeable/Dispatcher.sol");
var Target = artifacts.require("./contracts/Target.sol");
var TargetV2 = artifacts.require("./contracts/TargetV2.sol");
var ErrorTarget = artifacts.require("./contracts/ErrorTarget.sol");
var StateErrorTarget = artifacts.require("./contracts/StateErrorTarget.sol");
var NotVerifyingTarget = artifacts.require("./contracts/NotVerifyingTarget.sol");
const expectThrow = require('daonomic-tests').expectThrow;
contract('Upgradeable', function(accounts) {
it("should let upgrade to v2", async () => {
var target = await Target.deployed();
var targetV2 = await TargetV2.deployed();
var dispatcher = await Dispatcher.deployed();
var dispatcherAsTarget = Target.at(dispatcher.address);
var dispatcherAsTargetV2 = TargetV2.at(dispatcher.address);
await dispatcherAsTarget.upgrade(targetV2.address, {from: accounts[2]})
await dispatcherAsTargetV2.increaseIntState();
await dispatcherAsTargetV2.setAdmin(accounts[1]);
assert.equal(await dispatcherAsTargetV2.intState.call(), 1);
});
it("should not let upgrade if checkAdmin fails", async () => {
var target = await Target.deployed();
var dispatcher = await Dispatcher.deployed();
var dispatcherAsTargetV2 = TargetV2.at(dispatcher.address);
await expectThrow(dispatcherAsTargetV2.upgrade(target.address));
});
it("should let upgrade if checkAdmin succeeds", async () => {
var target = await Target.deployed();
var dispatcher = await Dispatcher.deployed();
var dispatcherAsTargetV2 = TargetV2.at(dispatcher.address);
await dispatcherAsTargetV2.upgrade(target.address, {from: accounts[1]})
});
it("should not let upgrade if target can't be verified", async () => {
var dispatcher = await Dispatcher.deployed();
var dispatcherAsTarget = Target.at(dispatcher.address);
var errorTarget = await ErrorTarget.deployed();
await expectThrow(dispatcherAsTarget.upgrade(errorTarget.address));
});
it("should not not let upgrade if intState can't be verified", async () => {
var dispatcher = await Dispatcher.deployed();
var dispatcherAsTarget = Target.at(dispatcher.address);
var stateErrorTarget = await StateErrorTarget.deployed();
await expectThrow(dispatcherAsTarget.upgrade(stateErrorTarget.address));
});
it("but it'll let upgrade if no check present", async () => {
var dispatcher = await Dispatcher.deployed();
var dispatcherAsTarget = Target.at(dispatcher.address);
var stateErrorTarget = await StateErrorTarget.deployed();
var notVerifyingTarget = await NotVerifyingTarget.deployed();
await dispatcherAsTarget.setStringState("test state");
await dispatcherAsTarget.upgrade(notVerifyingTarget.address);
await dispatcherAsTarget.upgrade(stateErrorTarget.address);
assert.notEqual(await dispatcherAsTarget.stringState.call(), "test state");
await dispatcherAsTarget.upgrade(notVerifyingTarget.address);
assert.equal(await dispatcherAsTarget.stringState.call(), "test state");
});
});