-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfirmProject.ts
154 lines (144 loc) · 4.26 KB
/
confirmProject.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import * as anchor from "@project-serum/anchor";
import { Program } from "@project-serum/anchor";
import { Mate } from "../target/types/mate";
import { assert } from "chai"
import * as web3 from "@solana/web3.js"
import { PublicKey, SystemProgram } from "@solana/web3.js"
describe("An user can confirm his prticipation in a project", () => {
const anchorProvider = anchor.AnchorProvider.env();
anchor.setProvider(anchorProvider);
const program = anchor.workspace.Mate as Program<Mate>;
const name = "Project i'm part of"
const group = "Groupß"
const project_type = "project_type"
const ratio = 10
const currency = "SOL"
const amount = new anchor.BN(20)
const common_expenses = new anchor.BN(2)
const milestones = 0;
const client = new PublicKey('5xot9PVkphiX2adznghwrAuxGs2zeWisNSxMW6hU6Hkj')
const member0 = (program.provider as anchor.AnchorProvider).wallet;
const member1 = new PublicKey("EjPpXXDykPawauyZHsBMtxGwG7K4iFmxdvB6ockM56ZN")
const member2 = new PublicKey("CUtKCTar8gb5VYCDWbX5yFMVrhbnod9aCNf4cfhD2qPK")
const member3 = new PublicKey("6ivuS4xbpr61vMgMwPPnvhSw2sWs4fpKFt7baoiK3s3S")
const member4 = new PublicKey("8i5WmmdGgibZ36h3xLEDsQ6N8QY71RpZqUoVieYZx1GL")
const member5 = new PublicKey("GpMhH3hTKdGnJqAaXM9tZoq1GUSFMFNxN8bE5vZzrK6x")
const member6 = new PublicKey("3dwJ6Xr534orZTwa8n2SJZQNeHY2FWLJ6SpxitBz3wva")
const member7 = new PublicKey("5G2xXJ46kPo3R4SNmFRCg2z2ru68LCoeoWvZK3FfUGMF")
const member8 = new PublicKey("6R3MnM7LrMpLSs5NRnniEQ6kDxTHfpY8Qg9hXMKVkaf4")
const member9 = new PublicKey("EjPpXXDykPawauyZHsBMtxGwG7K4iFmxdvB6ockM56ZN")
const payments = [
{
member: member0.publicKey,
amount: new anchor.BN(1),
},
{
member: member1,
amount: new anchor.BN(10),
},
{
member: member2,
amount: new anchor.BN(100),
},
{
member: member3,
amount: new anchor.BN(20),
},
{
member: member4,
amount: new anchor.BN(30),
},
{
member: member5,
amount: new anchor.BN(40),
},
{
member: member6,
amount: new anchor.BN(50),
},
{
member: member7,
amount: new anchor.BN(60),
},
{
member: member8,
amount: new anchor.BN(70),
},
{
member: member9,
amount: new anchor.BN(81),
},
] as unknown as Mate["types"][0]
const [pdaPublicKey] = web3.PublicKey.findProgramAddressSync(
[Buffer.from("project"), Buffer.from(name), Buffer.from(group)],
program.programId,
)
const [groupPublicKey] = web3.PublicKey.findProgramAddressSync(
[Buffer.from("group"), Buffer.from(name)],
program.programId,
)
it("Create a group", async () => {
await program.methods
.createGroup(
name,
10,
[
member0.publicKey,
member1,
member2,
member3,
member4,
member5,
member6,
member7,
member8,
member9,
]
)
.accounts({
group: groupPublicKey,
payer: anchorProvider.wallet.publicKey,
systemProgram: web3.SystemProgram.programId,
})
.rpc()
const storedGroup = await program.account.group.fetch(groupPublicKey)
console.log(storedGroup)
assert.equal(storedGroup.name, name)
});
it(" create a project", async () => {
await program.methods
.createProject(
name,
group,
project_type,
ratio,
payments,
common_expenses,
currency,
amount,
milestones,
new anchor.BN(Date.now()),
new anchor.BN(Date.now()),
client
)
.accounts({
project: pdaPublicKey,
payer: anchorProvider.wallet.publicKey,
systemProgram: web3.SystemProgram.programId,
})
.rpc()
const storedProject = await program.account.project.fetch(pdaPublicKey)
console.log(storedProject)
assert.equal(storedProject.name, name)
});
it("Confirm my participation...", async () => {
const tx = await program.methods.confirmProjectParticipation()
.accounts({
user: member0.publicKey,
project: pdaPublicKey,
systemProgram: SystemProgram.programId,
})
.rpc();
console.log(`https://explorer.solana.com/tx/${tx}?cluster=devnet`);
});
});