-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test__examples__Account.js
67 lines (58 loc) · 2.21 KB
/
test__examples__Account.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
"use strict";
const Account = artifacts.require("Account");
//
contract("test/examples/Account.sol", (accounts) => {
const owner_Account = accounts[2];
const owner_Account__name = "Jain";
const owner_Account__new_name = 'Ted';
const owner_Account__new_owner = accounts[9];
//
afterEach(async () => {
const account = await Account.deployed();
if (await account.owner() === owner_Account__new_owner) {
await account.changeOwner(owner_Account, { from: owner_Account__new_owner });
}
if (await account.name() !== owner_Account__name) {
await account.changeName(owner_Account__name, { from: owner_Account });
}
});
//
it("Account.changeName allowed for owner", async () => {
const account = await Account.deployed();
await account.changeName(owner_Account__new_name, { from: owner_Account });
return assert.equal(owner_Account__new_name, await account.name(), "Failed to change name");
});
//
it("Account.changeName disallowed for non-owner", async () => {
const account = await Account.deployed();
try {
await account.changeName(owner_Account__new_name, { from: owner_Account__new_owner });
} catch (error) {
if (error.reason === "Account.changeName: message sender not an owner") {
return assert.isTrue(true, "Wat!?");
}
console.error(error);
}
return assert.isTrue(false, "Failed to catch expected error reason");
});
//
it("Account.changeOwner allowed for owner", async () => {
const account = await Account.deployed();
await account.changeOwner(owner_Account__new_owner, { from: owner_Account });
return assert.equal(owner_Account__new_owner, await account.owner(), "Failed to change owner");
assert.isTrue(true);
});
//
it("Account.changeOwner disallowed for non-owner", async () => {
const account = await Account.deployed();
try {
await account.changeOwner(owner_Account__new_owner, { from: owner_Account__new_owner });
} catch (error) {
if (error.reason === "Account.changeOwner: message sender not an owner") {
return assert.isTrue(true, "Wat!?");
}
console.error(error);
}
return assert.isTrue(false, "Failed to catch expected error reason");
});
});