This repository has been archived by the owner on Mar 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathguestbook.js
82 lines (62 loc) · 2.44 KB
/
guestbook.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
72
73
74
75
76
77
78
79
80
81
82
const MultiGuestbook = artifacts.require("MultiGuestbook");
const GuestbookLib = artifacts.require("GuestbookLib");
const { forGuestbook } = require("./helpers");
contract("MultiGuestbook", function(accounts) {
const alice = accounts[0];
const bob = accounts[1];
const calhoun = accounts[2];
let guestbook;
let helpers;
before("setup tests", async function() {
guestbook = await MultiGuestbook.deployed();
helpers = await forGuestbook(guestbook, GuestbookLib);
});
it("returns guestbook signatures via ABI", async function() {
const message = "hello world!";
/*
* sign guestbook's own guestbook using ENS name for both function
* parameter and tx parameter
*
* to debug this transaction: comment this out and uncomment the next line
*/
await guestbook.sign("multi.guestbook", message, { from: "alice.name" });
// await debug(guestbook.sign("multi.guestbook", message, { from: "alice.name" }));
/*
* read guestbook signatures via external view
*
* to debug this call: comment this out and uncomment the line below,
* run `truffle test --debug`
*/
const signatures = await guestbook.signatures("multi.guestbook");
// const signatures = await debug(guestbook.signatures("multi.guestbook"));
// find alice's message
const { contents } = signatures.find( ({ author }) => author === alice );
assert.equal(contents, message);
});
it("stores guestbook messages", async function() {
const message = "interesting concept, perhaps... -bob";
// use ENS name for guestbook address and sender
await guestbook.sign("multi.guestbook", message, { from: "bob.name" });
const { readGuestbookStorage } = helpers;
// read storage and find message from bob
const messages = await readGuestbookStorage(guestbook.address);
const { contents } = messages.find(
({ author }) => author === bob
);
assert.equal(contents, message);
});
it("emits events", async function() {
const message = "no like button?";
// capture receipt to inspect event
const { receipt } = await guestbook.sign(
"multi.guestbook", message, { from: "calhoun.name" }
);
const { readSignGuestbookEvent } = helpers;
// check raw log matches signed guestbook message
const { author, contents } = await readSignGuestbookEvent(
receipt.rawLogs[0]
);
assert.equal(author, calhoun);
assert.equal(contents, message);
});
});