-
Notifications
You must be signed in to change notification settings - Fork 6
/
test.js
294 lines (274 loc) · 11 KB
/
test.js
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
287
288
289
290
291
292
293
294
require("dotenv").config();
const xrpl = require("xrpl");
const app = require("./index.js");
const supertest = require("supertest");
const requestWithSupertest = supertest(app);
const assert = require("assert");
var should = require("chai").should();
// Mock data for tests
const minter = xrpl.Wallet.fromSeed(process.env.WALLET_SEED).address;
const testUser = {
publicKey:
"ED3467208169A8978DD8A66D20D95E8AC63DD2B7675A5A072A49C58832F93A7BF0",
privateKey:
"EDEC608D34F5825C1EDAFC561DE2BBCB12E953CDD5D725D1691EABFECF253A195D",
classicAddress: "rJnCJZZXSSnuDi9YVgrAatVqSvktTeXr5r",
seed: "sEdTG44pDuiojoi7pH9R5qzytEuYurd",
};
const testNftId =
"000300003CBB7B1E0212681492733BDA77986A6A7C4C2B4A2DCBAB9D00000002";
let walletForSignatureVerification = {
publicKey:
"ED57D41105FC480545763677D2100C8949324A97811FE5CB45594B5E73991BBF92",
privateKey:
"EDE60F3996E5A0855FEF0C1E31A894D5085294A12D364FB11421F37B7683A1F6B2",
classicAddress: "raY33uxEbZFg7YS1ofFRioeENLsVdCgpC5",
seed: "sEdVMJSLjuTAjaSeeZ6TEkpUWuTS83j",
};
const myWallet = xrpl.Wallet.fromSeed(walletForSignatureVerification.seed);
let txJSON;
const txNoMemo = {
Account: walletForSignatureVerification.address,
TransactionType: "AccountSet",
Fee: "12",
Sequence: 5,
Domain: "6578616D706C652E636F6D",
SetFlag: 5,
MessageKey:
"03AB40A0490F9B7ED8DF29D246BF2D6269820A0EE7742ACDD457BEA7C7D0931EDB",
};
const txWrongMemo = {
Account: walletForSignatureVerification.classicAddress,
TransactionType: "AccountSet",
Fee: "12",
Sequence: 5,
Domain: "6578616D706C652E636F6D",
SetFlag: 5,
MessageKey:
"03AB40A0490F9B7ED8DF29D246BF2D6269820A0EE7742ACDD457BEA7C7D0931EDB",
Memos: [
{
Memo: {
MemoData: xrpl.convertStringToHex("13"),
},
},
],
};
// Empty variables for tests
let newUser;
let testEvent;
let testMemoId = 0;
//let nftOffer;
// API tests
describe("Testing typical user flow", function () {
it("Getting new wallet account", async () => {
return requestWithSupertest.get("/api/getNewAccount").then(async (r) => {
console.log(JSON.parse(r.text).result);
newUser = await JSON.parse(r.text).result;
r.res.statusCode.should.equal(200);
JSON.parse(r.text).result.should.be.a("object");
});
}).timeout(60000);
it("Minting NFTs for new event", async () => {
return requestWithSupertest
.get(
`/api/mint?walletAddress=${testUser.classicAddress}&tokenCount=3&url=ipfs://QmQDDD1cNgnyhPC4pBLZKhVeu12oyfCAJoWr1Qc1QgbkPN&title=test_title&desc=test_description&loc=Warsaw`
)
.then(async (r) => {
console.log(JSON.parse(r.text).result);
testEvent = await JSON.parse(r.text).result;
r.res.statusCode.should.equal(200);
JSON.parse(r.text).result.should.be.a("object");
});
}).timeout(600000);
/**
* * Only uncomment if you want to test minting for 300 NFTs at the same time to see if ticketing and paginating works correctly
* * WARNING! It might take a really long time to complete
it("Minting NFTs with tokenCount exceding 250", async () => {
return requestWithSupertest
.get(
`/api/mint?walletAddress=${testUser.classicAddress}&tokenCount=300&url=ipfs://QmQDDD1cNgnyhPC4pBLZKhVeu12oyfCAJoWr1Qc1QgbkPN&title=test_title&desc=test_description&loc=Warsaw`
)
.then(async (r) => {
console.log(JSON.parse(r.text).result);
testEvent = await JSON.parse(r.text).result;
r.res.statusCode.should.equal(200);
JSON.parse(r.text).result.should.be.a("object");
});
}).timeout(6000000);
*/
it("Checking if it's possible to claim NFT for event", async () => {
return requestWithSupertest
.get(
`/api/claim?walletAddress=${testUser.classicAddress}&minter=${minter}&eventId=${testEvent.eventId}&type=1`
)
.then((r) => {
// console.log(JSON.parse(r.text).result.length);
r.res.statusCode.should.equal(200);
// JSON.parse(r.text).result.should.be.a("object");
// JSON.parse(r.text).result.should.be.a("array");
JSON.parse(r.text).status.should.equal("success");
});
}).timeout(600000);
it("Claiming offer for NFT from event", async () => {
return requestWithSupertest
.get(
`/api/claim?walletAddress=${myWallet.classicAddress}&minter=${minter}&eventId=${testEvent.eventId}&type=2`
)
.then(async (r) => {
// console.log(JSON.parse(r.text).result.length);
const nftOffer = JSON.parse(r.text).offer;
console.log("offer ", nftOffer);
r.res.statusCode.should.equal(200);
// JSON.parse(r.text).result.should.be.a("object");
// JSON.parse(r.text).result.should.be.a("array");
JSON.parse(r.text).status.should.equal("transferred");
const client = new xrpl.Client(process.env.SELECTED_NETWORK);
await client.connect();
const transactionBlob = {
TransactionType: "NFTokenAcceptOffer",
Account: myWallet.classicAddress,
NFTokenSellOffer: nftOffer.nft_offer_index.toString(),
};
const tx = await client.submitAndWait(transactionBlob, {
wallet: myWallet,
});
await client.disconnect();
console.log(tx.result.meta.TransactionResult);
});
}).timeout(600000);
it("Looking up if the test user is on the attendees list for test event", async () => {
return requestWithSupertest
.get(`/api/attendees?minter=${minter}&eventId=${testEvent.eventId}`)
.then((r) => {
console.log(JSON.parse(r.text));
r.res.statusCode.should.equal(200);
JSON.parse(r.text).result.should.be.a("array");
JSON.parse(r.text).result[0].user.should.equal(myWallet.classicAddress);
});
}).timeout(600000);
it("Trying to verify NFT ownership before obtaining verification ID", async () => {
txJSON = {
Account: myWallet.address,
TransactionType: "AccountSet",
Fee: "12",
Sequence: 5,
Domain: "6578616D706C652E636F6D",
SetFlag: 5,
MessageKey:
"03AB40A0490F9B7ED8DF29D246BF2D6269820A0EE7742ACDD457BEA7C7D0931EDB",
Memos: [
{
Memo: {
MemoData: xrpl.convertStringToHex(testMemoId.toString()),
},
},
],
};
const signature = await myWallet.sign(txJSON);
return requestWithSupertest
.get(
`/api/verifyOwnership?walletAddress=${walletForSignatureVerification.classicAddress}&signature=${signature.tx_blob}&minter=${minter}&eventId=${testEvent.eventId}`
)
.then((r) => {
console.log(JSON.parse(r.text));
r.res.statusCode.should.equal(500);
JSON.parse(r.text).statusText.should.be.a("string");
JSON.parse(r.text).statusText.should.equal(
`Error: Wallet address '${walletForSignatureVerification.classicAddress}' doesn't have the verification ID generated for it yet. Please start the verification process by calling 'startVerification' and including the returned value as part of the memo in your signed transaction when calling this function.`
);
});
}).timeout(600000);
it("Trying to verify NFT ownership with signature from wrong address", async () => {
txJSON = {
Account: myWallet.address,
TransactionType: "AccountSet",
Fee: "12",
Sequence: 5,
Domain: "6578616D706C652E636F6D",
SetFlag: 5,
MessageKey:
"03AB40A0490F9B7ED8DF29D246BF2D6269820A0EE7742ACDD457BEA7C7D0931EDB",
Memos: [
{
Memo: {
MemoData: xrpl.convertStringToHex(testMemoId.toString()),
},
},
],
};
const signature = await myWallet.sign(txJSON);
return requestWithSupertest
.get(
`/api/verifyOwnership?walletAddress=${testUser.classicAddress}&signature=${signature.tx_blob}&minter=${minter}&eventId=${testEvent.eventId}`
)
.then((r) => {
console.log(JSON.parse(r.text));
r.res.statusCode.should.equal(500);
JSON.parse(r.text).statusText.should.be.a("string");
JSON.parse(r.text).statusText.should.equal(
`Error: Signature wasn't signed by provided wallet address '${testUser.classicAddress}'. Please provide correct signature and try again.`
);
});
}).timeout(600000);
it("Obtaining random ID for verification process", async () => {
return requestWithSupertest
.get(
`/api/startVerification?walletAddress=${walletForSignatureVerification.classicAddress}`
)
.then(async (r) => {
testMemoId = await JSON.parse(r.text).result;
txJSON.Memos[0].Memo = {
MemoData: xrpl.convertStringToHex(
await JSON.parse(r.text).result.toString()
),
};
console.log(JSON.parse(r.text));
r.res.statusCode.should.equal(200);
JSON.parse(r.text).result.should.be.a("string");
});
}).timeout(600000);
it("Trying to verify ownership with wrong signature", async () => {
const signature = await myWallet.sign(txJSON);
return requestWithSupertest
.get(
`/api/verifyOwnership?walletAddress=${walletForSignatureVerification.classicAddress}&signature=2280000000240000000268400000000000000C73210333C718C9CB716E0575454F4A343D46B284ED51151B9C7383524B82C10B262095744730450221009A4D99017F8FD6881D888047E2F9F90C068C09EC9308BC8526116B539D6DD44102207FAA7E8756F67FE7EE1A88884F120A00A8EC37E7D3E5ED3E02FEA7B1D97AA05581146C0994D3FCB140CAB36BAE9465137448883FA489&minter=${minter}&eventId=${testEvent.eventId}`
)
.then((r) => {
console.log(JSON.parse(r.text));
r.res.statusCode.should.equal(500);
JSON.parse(r.text).statusText.should.be.a("string");
JSON.parse(r.text).statusText.should.equal(
"Error: Signature is not valid."
);
});
}).timeout(600000);
it("Trying to verify ownership with wrong signature Memo", async () => {
const signature = await myWallet.sign(txWrongMemo);
return requestWithSupertest
.get(
`/api/verifyOwnership?walletAddress=${walletForSignatureVerification.classicAddress}&signature=${signature.tx_blob}&minter=${minter}&eventId=${testEvent.eventId}`
)
.then((r) => {
console.log(JSON.parse(r.text));
r.res.statusCode.should.equal(500);
JSON.parse(r.text).statusText.should.be.a("string");
JSON.parse(r.text).statusText.should.equal(
`Error: Memo '13' from signature does not match expected ID for the provided wallet address '${walletForSignatureVerification.classicAddress}'.`
);
});
}).timeout(600000);
it("Verifying ownership of NFT", async () => {
const signature = await myWallet.sign(txJSON);
return requestWithSupertest
.get(
`/api/verifyOwnership?walletAddress=${walletForSignatureVerification.classicAddress}&signature=${signature.tx_blob}&minter=${minter}&eventId=${testEvent.eventId}`
)
.then((r) => {
console.log(JSON.parse(r.text));
r.res.statusCode.should.equal(200);
JSON.parse(r.text).result.should.be.a("boolean");
JSON.parse(r.text).result.should.equal(true);
});
}).timeout(600000);
});