-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.ts
46 lines (38 loc) · 1.81 KB
/
test.ts
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
import Web3 from 'web3';
import { Contract } from 'web3-eth-contract';
export type EthBaseTypesWithMeta =
`string${string}` |
`string[${number}]` |
`bytes${string}` |
`bytes[${number}]` |
`address[${number}]` |
`bool[${number}]` |
`int${string}` |
`int[${number}]` |
`uint${string}` |
`uint[${number}]` |
`tuple[]` |
`tuple[${number}]`;
const SupplyChain = artifacts.require('SupplyChain');
const runTest = async () => {
try {
// Connect to the local Ethereum network
const web3 = new Web3('http://localhost:8545');
// Get the contract instance
const supplyChain: Contract = await SupplyChain.deployed();
// Assign the ranking partner
const rankingPartnerAddress = 'RANKING_PARTNER_ADDRESS'; // Replace with the ranking partner's Ethereum address
await supplyChain.methods.assignRankingPartner(rankingPartnerAddress).send({ from: rankingPartnerAddress });
// Record survey answers
const randomBoolean = () => Math.random() < 0.5;
await supplyChain.methods.recordCommitmentStatus(rankingPartnerAddress, randomBoolean()).send({ from: rankingPartnerAddress });
await supplyChain.methods.recordRiskFoundStatus(rankingPartnerAddress, randomBoolean()).send({ from: rankingPartnerAddress });
await supplyChain.methods.recordCommitmentChangedStatus(rankingPartnerAddress, randomBoolean()).send({ from: rankingPartnerAddress });
await supplyChain.methods.recordUpdatedNews(rankingPartnerAddress, randomBoolean()).send({ from: rankingPartnerAddress });
await supplyChain.methods.recordBackupPlan(rankingPartnerAddress, randomBoolean()).send({ from: rankingPartnerAddress });
console.log('Survey answers submitted successfully!');
} catch (error) {
console.error('Error:', error);
}
};
runTest();