-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateProject.ts
107 lines (102 loc) · 3.21 KB
/
createProject.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
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 } from "@solana/web3.js"
describe("We create a project", () => {
const anchorProvider = anchor.AnchorProvider.env();
anchor.setProvider(anchorProvider);
const program = anchor.workspace.Mate as Program<Mate>;
it("Can create a project", async () => {
const name = "Project's Name "
const group = "Groupß"
const project_type = "project_type"
const ratio = 10
const common_expenses = new anchor.BN(2)
const currency = "SOL"
const amount = new anchor.BN(20)
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,
)
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)
});
});