-
Notifications
You must be signed in to change notification settings - Fork 0
/
superteam-dao-contract.ts
286 lines (245 loc) · 11.9 KB
/
superteam-dao-contract.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
import * as anchor from "@project-serum/anchor";
import { SuperteamDaoContract } from "../target/types/superteam_dao_contract";
import {airdrop} from "./helper/airdrop";
import { Program, AnchorProvider, BN, Wallet } from '@project-serum/anchor';
import { Token, TOKEN_PROGRAM_ID } from '@solana/spl-token';
import * as bs58 from "bs58";
import {
Connection,
clusterApiUrl,
Keypair,
LAMPORTS_PER_SOL,
BlockTimestamp,
SystemProgram,
PublicKey
} from "@solana/web3.js";
import {findPDAIdentifier, findPDAProposal, getPage} from "./helper/setup";
import * as constants from "./constants";
import {getTokenBalance, mintTokenAToUser} from "./helper/helper";
import {MINT_A_AMOUNT, MINT_A_DECIMALS} from "./constants";
const provider = AnchorProvider.env()
anchor.setProvider(provider);
describe("superteam-dao-contract", () => {
const program = anchor.workspace.SuperteamDaoContract as Program<SuperteamDaoContract>;
const airdropSolAmount = 2;
let payer = anchor.web3.Keypair.generate();
let sender = anchor.web3.Keypair.generate();
let receiver = anchor.web3.Keypair.generate();
let applicantProposal, applicantProposal1, applicantProposal2 : anchor.web3.PublicKey;
let txn, txn1, txn2: String;
let bump: number;
let mintA;
const delay = ms => new Promise(res => setTimeout(res, ms));
before("Boilerplates", async () => {
let secondDelay = 5;
await delay(1000*secondDelay);
await airdrop(provider, sender.publicKey, airdropSolAmount)
await delay(1000*secondDelay);
await airdrop(provider, payer.publicKey, airdropSolAmount)
await delay(1000*secondDelay);
await airdrop(provider, receiver.publicKey, airdropSolAmount)
});
it("[Applicant flow] initialize identifier and proposal", async () => {
txn = "3danKMRy4oyf4mD7Sun3FtnHxQGsHyxJwxBzHN1CWzaRdK6vjwEUH6gv5yNN2Cp6SPnUxwSHYbuimkNyX2zm24bZ";
txn1 = "65K56thKZjgD5VNwq4g2HYQYWz2qvTkoy2YXb5zssbHZm6RvPFDrP26xiFMKyLRV1dDv6mR44DENeDfL771QXZJK";
txn2 = "2XZ7GSVsEiMW14DxUQc2fLU3doU7NpJgshJVWELc5VNPsfqtZ89yxzoennbzYEuJPLXoafvDjCfyx3giC2J6iSsL";
// Create our Token A Mint
mintA = new PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v");
[applicantProposal, bump] = await findPDAProposal(txn.substring(0, 32), txn.substring(32, 64), txn.substring(64, 88), sender.publicKey, receiver.publicKey, program)
await program.methods.createProposal(txn.substring(0, 32), txn.substring(32, 64), txn.substring(64, 88), sender.publicKey, receiver.publicKey, "https://upload.wikimedia.org/wikipedia/en/b/b9/Solana_logo.png",
"Orca summer Winner", "The analogies and problems used in these experiments were not specific to any domain of expertise and used fantasy problems relying only on linguistic descriptions, The semantic descriptions of the devices were varied, but the pictures were identical for both conditions, The following descriptions focus on the local purge in each town and the points at which the local and legal purges diverged.", mintA, "gamefi", new BN(100*(10**MINT_A_DECIMALS)))
.accounts({
proposal: applicantProposal,
payer: payer.publicKey,
systemProgram: SystemProgram.programId,
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
})
.signers([payer])
.rpc();
const dataApplicantProposal = await program.account.proposal.fetch(applicantProposal);
console.log("[proposal account] Create result: ", dataApplicantProposal);
[applicantProposal1, bump] = await findPDAProposal(txn1.substring(0, 32), txn1.substring(32, 64), txn1.substring(64, 88), sender.publicKey, receiver.publicKey, program)
await program.methods.createProposal(txn1.substring(0, 32), txn1.substring(32, 64), txn1.substring(64, 88), sender.publicKey, receiver.publicKey, "https://upload.wikimedia.org/wikipedia/en/b/b9/Solana_logo.png",
"Orca summer 2nd", "", mintA, "defi", new BN(100*(10**MINT_A_DECIMALS)))
.accounts({
proposal: applicantProposal1,
payer: payer.publicKey,
systemProgram: SystemProgram.programId,
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
})
.signers([payer])
.rpc();
[applicantProposal2, bump] = await findPDAProposal(txn2.substring(0, 32), txn2.substring(32, 64), txn2.substring(64, 88), sender.publicKey, receiver.publicKey, program)
await program.methods.createProposal(txn2.substring(0, 32), txn2.substring(32, 64), txn2.substring(64, 88), sender.publicKey, receiver.publicKey, "https://upload.wikimedia.org/wikipedia/en/b/b9/Solana_logo.png",
"Solcan summer 3rd", "", mintA, "gamefi", new BN(100*(10**MINT_A_DECIMALS)))
.accounts({
proposal: applicantProposal2,
payer: payer.publicKey,
systemProgram: SystemProgram.programId,
rent: anchor.web3.SYSVAR_RENT_PUBKEY,
})
.signers([payer])
.rpc();
});
it("[sender] approve proposal", async () => {
await program.methods.senderApproveProposal()
.accounts({
proposal: applicantProposal,
sender: sender.publicKey,
systemProgram: SystemProgram.programId,
})
.signers([sender])
.rpc();
const dataApplicantProposal = await program.account.proposal.fetch(applicantProposal);
console.log("[proposal account] sender approve : ", dataApplicantProposal);
});
it("[receiver] approve proposal", async () => {
await program.methods.receiverApproveProposal()
.accounts({
proposal: applicantProposal,
receiver: receiver.publicKey,
systemProgram: SystemProgram.programId,
})
.signers([receiver])
.rpc();
const dataApplicantProposal = await program.account.proposal.fetch(applicantProposal);
console.log("[proposal account] sender approve : ", dataApplicantProposal);
});
it("[receiver] update nft", async () => {
await program.methods.updateNft(new PublicKey("3J11Q7h5PhxvbKorARKHnG3rkqoqJqLGisCt8WWZYUBT"))
.accounts({
proposal: applicantProposal,
receiver: receiver.publicKey,
systemProgram: SystemProgram.programId,
})
.signers([receiver])
.rpc();
const dataApplicantProposal = await program.account.proposal.fetch(applicantProposal);
console.log("[proposal account] update nft approve : ", dataApplicantProposal);
});
it("[submitter] cancel proposal", async () => {
const balanceBefore = await provider.connection.getBalance(payer.publicKey);
console.log("[payer balance before close proposal]: ", balanceBefore);
const balanceProposalAccount2 = await provider.connection.getBalance(applicantProposal2);
console.log("[applicantProposal2 balance]: ", balanceProposalAccount2);
await program.methods.cancelProposal()
.accounts({
proposal: applicantProposal2,
payer: payer.publicKey,
systemProgram: SystemProgram.programId,
})
.signers([payer])
.rpc();
const balanceAfter = await provider.connection.getBalance(payer.publicKey);
console.log("[payer balance after close proposal]: ", balanceAfter);
});
it("[sender] reject proposal", async () => {
await program.methods.senderRejectProposal()
.accounts({
proposal: applicantProposal1,
sender: sender.publicKey,
systemProgram: SystemProgram.programId,
})
.signers([sender])
.rpc();
const dataApplicantProposal1 = await program.account.proposal.fetch(applicantProposal1);
console.log("[proposal account] sender approve : ", dataApplicantProposal1);
});
it("[submitter] close proposal", async () => {
const balanceBefore = await provider.connection.getBalance(payer.publicKey);
console.log("[payer balance before close proposal]: ", balanceBefore);
const balanceProposalAccount1 = await provider.connection.getBalance(applicantProposal1);
console.log("[applicantProposal1 balance]: ", balanceProposalAccount1);
await program.methods.cancelProposal()
await program.methods.closeProposal()
.accounts({
proposal: applicantProposal1,
submitter: payer.publicKey,
payer: receiver.publicKey,
systemProgram: SystemProgram.programId,
})
.signers([receiver])
.rpc();
const balanceAfter = await provider.connection.getBalance(payer.publicKey);
console.log("[payer balance after close proposal]: ", balanceAfter);
});
// it("filter proposal by sender ", async () => {
// const connection = new Connection(clusterApiUrl('devnet'))
// let programId = new PublicKey("2kAE3hehkVtyjfwBE9mMYgzMMD4uH6s6GLVwzuK179pV");
// let sender = new PublicKey("DbkRkU7N21CHaPPBHvDhCpt3DpHjSqesiQFY84ebGneL");
// const proposalsBySender = await connection.getProgramAccounts(programId, {
// filters: [
// { memcmp: { offset: 40, bytes: sender.toBase58() } }, // Ensure it's a CandyMachine account.
// ],
// });
// const accountPublicKeys = proposalsBySender.map(account => account.pubkey)
// const perPage = 6
// const page1 = await getPage(1, perPage, accountPublicKeys, program)
// console.log(page1)
//
// });
// it("get proposal by transaction, sender, receiver ", async () => {
// let transaction = "3danKMRy4oyf4mD7Sun3FtnHxQGsHyxJwxBzHN1CWzaRdK6vjwEUH6gv5yNN2Cp6SPnUxwSHYbuimkNyX2zm24bZ"
// const proposalBySender = await program.account.proposal.all([
// {
// memcmp: {
// offset: 8, // Discriminator.
// bytes: receiver.publicKey.toBase58(),
// },
// },
// {
// memcmp: {
// offset: 40, // Discriminator.
// bytes: sender.publicKey.toBase58(),
// },
// },
// {
// memcmp: {
// offset: 118, // Discriminator.
// bytes: bs58.encode(Buffer.from(transaction)),
// },
// }
// ]);
//
// console.log(proposalBySender);
//
// });
it("get proposal by receiver ", async () => {
const proposal = await program.account.proposal.all([
{
memcmp: {
offset: 8, // Discriminator.
bytes: receiver.publicKey.toBase58(),
},
},
]);
console.log(proposal);
});
it("get proposal by sender ", async () => {
const proposal = await program.account.proposal.all([
{
memcmp: {
offset: 40, // Discriminator.
bytes: sender.publicKey.toBase58(),
},
},
]);
console.log(proposal);
});
it("get proposal by submitter ", async () => {
const proposal = await program.account.proposal.all([
{
memcmp: {
offset: 72, // Discriminator.
bytes: payer.publicKey.toBase58(),
},
},
]);
console.log(proposal);
});
// it("check proposal is exist", async () => {
// let key = new PublicKey("B9zsa2U1qgYMnsxAr6dm96hJkiGHcxxcnZTNTwmTVJGN")
// const proposal = await program.account.proposal.fetch(key)
// console.log(proposal)
// })
});