-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroup-service.test.ts
84 lines (67 loc) · 3.14 KB
/
group-service.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
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
83
84
import {describe, expect, test} from '@jest/globals';
import {setup, GroupService, TransactionService} from '../src'
import * as dotenv from 'dotenv';
dotenv.config();
/**
* Test creating a group with 1 member
* Add one more member and change threshold to 2
* Add two more members to the group
* Change threshold to 2
*/
describe('Group Service', () => {
const timeout = 60000;
let safeAddress;
const setupConfig = {pk: process.env.PRIVATE_KEY1!, rpcUrl: process.env.RPC_URL!, gelatoRelayApiKey: process.env.GELATO_RELAY_API_KEY!, appName: process.env.APP_NAME!};
const member1 = {address: process.env.OWNER1!, key: process.env.PRIVATE_KEY1!};
const member2 = {address: process.env.OWNER2!, key: process.env.PRIVATE_KEY2!};
const member3 = {address: process.env.OWNER3!, key: process.env.PRIVATE_KEY3!};
const member4 = {address: process.env.OWNER4!, key: process.env.PRIVATE_KEY4!};
test('should create a group', async () => {
setup(setupConfig);
safeAddress = await GroupService.createGroup([member1.address], 1);
console.log('safeAddress => ', safeAddress);
expect(safeAddress).toBeTruthy();
// Get group info
const groupInfo = await GroupService.getGroupInfo(safeAddress);
expect(groupInfo.owners.includes(member1.address)).toBe(true);
expect(groupInfo.owners.length).toBe(1);
expect(groupInfo.threshold).toBe(1);
}, timeout);
test('should add a group member and change minApprovals to 2', async () => {
setup(setupConfig);
const txHash = await GroupService.addMember(safeAddress, member2.address, 2);
console.log(" txHash => ", txHash);
expect(txHash).toBeTruthy();
// Get group info
const groupInfo = await GroupService.getGroupInfo(safeAddress);
expect(groupInfo.owners.includes(member2.address)).toBe(true);
expect(groupInfo.owners.length).toBe(2);
expect(groupInfo.threshold).toBe(2);
}, timeout);
test('should batch add two group members', async () => {
setup(setupConfig);
const {safeTxHash} = await GroupService.addMembers(safeAddress, [member3.address, member4.address]);
// Add another approval and auto execute
setup({...setupConfig, pk: member2.key});
const txHash = await TransactionService.voteTransaction(safeAddress, safeTxHash!);
console.log('txHash => ', txHash);
expect(txHash).toBeTruthy();
// Get group info
const groupInfo = await GroupService.getGroupInfo(safeAddress);
expect(groupInfo.owners.includes(member3.address)).toBe(true);
expect(groupInfo.owners.includes(member4.address)).toBe(true);
expect(groupInfo.owners.length).toBe(4);
expect(groupInfo.threshold).toBe(2);
}, timeout);
test('should change min approvals', async () => {
setup(setupConfig);
const {safeTxHash} = await GroupService.changeMinApprovals(safeAddress, 3);
// Add another approval and auto execute
setup({...setupConfig, pk: member2.key});
const txHash = await TransactionService.voteTransaction(safeAddress, safeTxHash!);
expect(txHash).toBeTruthy();
// Get group info
const groupInfo = await GroupService.getGroupInfo(safeAddress);
expect(groupInfo.threshold).toBe(3);
}, timeout);
});