forked from Tezos-India/TezAsia-2k23
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemotest.js
79 lines (57 loc) · 2.84 KB
/
demotest.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
const assert = require('assert');
const ganache = require('ganache-cli');
const Web3 = require('web3');
const web3 = new Web3(ganache.provider());
const compiledRecord = require('../truffle/build/data.json');
let accounts;
let record;
beforeEach(async () => {
accounts = await web3.eth.getAccounts();
record = await new web3.eth.Contract(JSON.parse(compiledRecord.interface))
.deploy({ data: compiledRecord.bytecode })
.send({ from: accounts[0], gas: '5000000' });
});
describe('Records', () => {
it('can deploy record contract', () => {
assert.ok(record.options.address);
});
it('can add record', async () => {
await record.methods.setDetails(
'001107020345', 'John', '0123456789', 'Male', '07/22/2222', 'O', 'Food', 'Antidepressants'
).send({ from: accounts[0], gas: '5000000' });
});
it('can retrieve all record address', async () => {
await record.methods.setDetails(
'001107020345', 'John', '0123456789', 'Male', '07/22/2222', 'O', 'Food', 'Antidepressants'
).send({ from: accounts[0], gas: '5000000' });
const allRecords = await record.methods.getPatients().call();
const owner = await record.methods.owner().call();
assert.equal(allRecords, owner);
});
it('can search for a patient', async () => {
await record.methods.setDetails(
'001107020345', 'John', '0123456789', 'Male', '07/22/2222', 'O', 'Food', 'Antidepressants'
).send({ from: accounts[0], gas: '5000000' });
const owner = await record.methods.owner().call();
names = await record.methods.searchPatientDemographic(owner).call();
assert.equal(names[0], '001107020345');
});
it('can create patient using multiple accounts', async () => {
await record.methods.setDetails(
'001107020345', 'John', '0123456789', 'Male', '07/22/2222', 'O', 'Food', 'Antidepressants'
).send({ from: accounts[0], gas: '5000000' });
await record.methods.setDetails(
'001107020345', 'John', '0123456789', 'Male', '07/22/2222', 'O', 'Food', 'Antidepressants'
).send({ from: accounts[1], gas: '5000000' });
const allRecords = await record.methods.getPatients().call();
assert.equal(allRecords[0], accounts[0]);
assert.equal(allRecords[1], accounts[1]);
});
it('can count number of records created by patient', async () => {
await record.methods.setDetails(
'001107020345', 'John', '0123456789', 'Male', '07/22/2222', 'O', 'Food', 'Antidepressants'
).send({ from: accounts[0], gas: '5000000' });
const patientCount = await record.methods.getPatientCount().call();
assert.equal(patientCount, 1);
});
});