Skip to content

Commit 0a5b091

Browse files
added RecordScanner integration tests
1 parent c0ed7e6 commit 0a5b091

File tree

3 files changed

+131
-5
lines changed

3 files changed

+131
-5
lines changed

sdk/src/record-scanner.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,13 @@ class RecordScanner implements RecordProvider {
188188
* @param {string} jobId The job id to check.
189189
* @returns {Promise<StatusResponse>} The status of the job.
190190
*/
191-
async checkStatus(jobId: string): Promise<StatusResponse> {
191+
async checkStatus(): Promise<StatusResponse> {
192192
try {
193193
const response = await this.request(
194194
new Request(`${this.url}/status`, {
195195
method: "POST",
196196
headers: { "Content-Type": "application/json" },
197-
body: JSON.stringify(jobId),
197+
body: JSON.stringify(this.uuid?.toString()),
198198
}),
199199
);
200200

@@ -347,7 +347,7 @@ class RecordScanner implements RecordProvider {
347347
}
348348
}
349349

350-
private computeUUID(vk: ViewKey): Field {
350+
computeUUID(vk: ViewKey): Field {
351351
// Construct the material needed for the Poseidon oracle.
352352
const inputs = [Field.newDomainSeparator(RECORD_DOMAIN), vk.toField(), Field.one()]
353353
// Calculate the uuid.
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
import { expect } from "chai";
2+
import { ViewKey } from "../src/node";
3+
import { RecordScanner } from "../src/record-scanner";
4+
5+
describe("RecordScanner", () => {
6+
const recordScannerUrl = process.env.RECORD_SCANNER_URL as string;
7+
const apiKey = process.env.KONG_API_KEY as string;
8+
const viewKeyStr = process.env.VIEW_KEY as string;
9+
const viewKey = new ViewKey(viewKeyStr);
10+
let recordScanner = new RecordScanner({ url: recordScannerUrl, apiKey });
11+
12+
it("should successfully register a view key", async () => {
13+
let response = await recordScanner.register(viewKey, 0);
14+
expect(response.uuid).to.equal(recordScanner.computeUUID(viewKey).toString());
15+
});
16+
17+
it("should successfully get owned records", async () => {
18+
let response = await recordScanner.findRecords({
19+
filter: {
20+
program: "credits.aleo",
21+
records: ["credits"],
22+
start: 0,
23+
end: 10332941,
24+
},
25+
response: {
26+
block_height: true,
27+
program_name: true,
28+
record_name: true,
29+
commitment: true,
30+
}
31+
});
32+
expect(response.length).to.equal(9);
33+
for (const record of response) {
34+
expect(record.program_name).to.equal("credits.aleo");
35+
expect(record.record_name).to.equal("credits");
36+
expect(record.block_height).to.be.greaterThan(0);
37+
expect(record.block_height).to.be.lessThan(10332941);
38+
expect(record.commitment).to.exist;
39+
expect(record.output_index).to.not.exist;
40+
}
41+
42+
response = await recordScanner.findRecords({
43+
filter: {
44+
program: "credits.aleo",
45+
records: ["credits"],
46+
start: 10000000,
47+
end: 10332941,
48+
},
49+
});
50+
expect(response.length).to.equal(3);
51+
for (const record of response) {
52+
expect(record.program_name).to.equal("credits.aleo");
53+
expect(record.record_name).to.equal("credits");
54+
expect(record.block_height).to.be.greaterThan(10000000);
55+
expect(record.block_height).to.be.lessThan(10332941);
56+
expect(record.commitment).to.exist;
57+
expect(record.output_index).to.exist;
58+
}
59+
});
60+
61+
it("should successfully get encrypted records", async () => {
62+
let response = await recordScanner.encryptedRecords({
63+
program: "credits.aleo",
64+
records: ["credits"],
65+
results_per_page: 50,
66+
response: {
67+
commitment: true,
68+
block_height: true,
69+
program_name: true,
70+
record_name: true,
71+
},
72+
});
73+
74+
expect(response.length).to.equal(50);
75+
for (const record of response) {
76+
expect(record.program_name).to.equal("credits.aleo");
77+
expect(record.record_name).to.equal("credits");
78+
expect(record.commitment).to.exist;
79+
expect(record.block_height).to.exist;
80+
expect(record.output_index).to.not.exist;
81+
}
82+
83+
response = await recordScanner.encryptedRecords({
84+
program: "credits.aleo",
85+
records: ["credits"],
86+
results_per_page: 30,
87+
});
88+
expect(response.length).to.equal(30);
89+
for (const record of response) {
90+
expect(record.program_name).to.equal("credits.aleo");
91+
expect(record.record_name).to.equal("credits");
92+
expect(record.commitment).to.exist;
93+
expect(record.block_height).to.exist;
94+
expect(record.output_index).to.exist;
95+
}
96+
});
97+
98+
it("should successfully check serial numbers", async () => {
99+
let response = await recordScanner.checkSerialNumbers([
100+
"2497968624879919117393326048350070098671407363450098197552864797993755823036field",
101+
"1050894655374138905808887909092891940183499902306462627909572997011712750387field",
102+
]);
103+
expect(response).to.deep.equal({
104+
"2497968624879919117393326048350070098671407363450098197552864797993755823036field": false,
105+
"1050894655374138905808887909092891940183499902306462627909572997011712750387field": false,
106+
});
107+
});
108+
109+
it("should successfully check tags", async () => {
110+
let response = await recordScanner.checkTags([
111+
"2726311268578079710210289900019159614843633435399431654197596897028642765098field",
112+
"448505083045691117285710413252063292683250969684463991322463606849073525242field",
113+
]);
114+
expect(response).to.deep.equal({
115+
"2726311268578079710210289900019159614843633435399431654197596897028642765098field": false,
116+
"448505083045691117285710413252063292683250969684463991322463606849073525242field": false,
117+
});
118+
});
119+
120+
it("should successfully get a job status", async () => {
121+
let response = await recordScanner.checkStatus();
122+
expect(response.synced).to.be.instanceOf(Boolean);
123+
expect(response.percentage).to.be.instanceOf(Number);
124+
})
125+
});

sdk/tests/record-scanner.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,13 +324,14 @@ describe("RecordScanner", () => {
324324
text: () => Promise.resolve(JSON.stringify({ synced: true, percentage: 100 })),
325325
json: () => Promise.resolve({ synced: true, percentage: 100 }),
326326
};
327+
recordScanner.setUuid(defaultAccount.viewKey());
327328
fetchStub.resolves(mockResponse);
328-
const statusResponse = await recordScanner.checkStatus("test-job-id");
329+
const statusResponse = await recordScanner.checkStatus();
329330
expect(statusResponse).to.deep.equal({ synced: true, percentage: 100 });
330331

331332
const request = fetchStub.firstCall.args[0] as Request;
332333
const body = await request.text();
333-
const expectedBody = JSON.stringify("test-job-id");
334+
const expectedBody = JSON.stringify(recordScanner.computeUUID(defaultAccount.viewKey()).toString());
334335
expect(body).to.equal(expectedBody);
335336
expect(request.url).to.equal("https://record-scanner.aleo.org/status");
336337
expect(request.method).to.equal("POST");

0 commit comments

Comments
 (0)