Skip to content

Commit

Permalink
update kwil to support results precision
Browse files Browse the repository at this point in the history
  • Loading branch information
outerlook committed Oct 24, 2024
1 parent 60cd07b commit b098f7c
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"lodash": "4.17.21"
},
"peerDependencies": {
"@kwilteam/kwil-js": "0.7.1"
"@kwilteam/kwil-js": "0.7.2"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "8.11.0",
Expand Down
12 changes: 6 additions & 6 deletions src/contracts-api/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class Stream {
*/
public async getRecord(input: GetRecordInput): Promise<StreamRecord[]> {
// TODO: change value to string when kwil-js is updated
const result = await this.call<{ date_value: string; value: number }[]>(
const result = await this.call<{ date_value: string; value: string }[]>(
"get_record",
[
ActionInput.fromObject({
Expand All @@ -186,7 +186,7 @@ export class Stream {
.mapRight((result) =>
result.map((row) => ({
dateValue: row.date_value,
value: row.value.toString(),
value: row.value,
})),
)
.throw();
Expand All @@ -196,7 +196,7 @@ export class Stream {
* Returns the index of the stream within the given date range
*/
public async getIndex(input: GetRecordInput): Promise<StreamRecord[]> {
const result = await this.call<{ date_value: string; value: number }[]>(
const result = await this.call<{ date_value: string; value: string }[]>(
"get_index",
[
ActionInput.fromObject({
Expand All @@ -211,7 +211,7 @@ export class Stream {
.mapRight((result) =>
result.map((row) => ({
dateValue: row.date_value,
value: row.value.toString(),
value: row.value,
})),
)
.throw();
Expand Down Expand Up @@ -248,7 +248,7 @@ export class Stream {
public async getFirstRecord(
input: GetFirstRecordInput,
): Promise<StreamRecord | null> {
const result = await this.call<{ date_value: string; value: number }[]>(
const result = await this.call<{ date_value: string; value: string }[]>(
"get_first_record",
[
ActionInput.fromObject({
Expand All @@ -264,7 +264,7 @@ export class Stream {
result
.map((result) => ({
dateValue: result.date_value,
value: result.value.toString(),
value: result.value,
}))
.unwrapOr(null),
)
Expand Down
20 changes: 10 additions & 10 deletions tests/integration/composedStream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ describe.sequential(
// Deploy child streams with initial data
// Child A: [2020-01-01: 1, 2020-01-02: 2, 2020-01-30: 3, 2020-02-01: 4, 2020-02-02: 5]
await deployPrimitiveStreamWithData(defaultClient, childAStreamId, [
{ dateValue: "2020-01-01", value: "1" },
{ dateValue: "2020-01-02", value: "2" },
{ dateValue: "2020-01-30", value: "3" },
{ dateValue: "2020-02-01", value: "4" },
{ dateValue: "2020-02-02", value: "5" },
{ dateValue: "2020-01-01", value: "1.000000000000000000" },
{ dateValue: "2020-01-02", value: "2.000000000000000000" },
{ dateValue: "2020-01-30", value: "3.000000000000000000" },
{ dateValue: "2020-02-01", value: "4.000000000000000000" },
{ dateValue: "2020-02-02", value: "5.000000000000000000" },
]);

// Child B: [2020-01-01: 3, 2020-01-02: 4, 2020-01-30: 5, 2020-02-01: 6, 2020-02-02: 7]
await deployPrimitiveStreamWithData(defaultClient, childBStreamId, [
{ dateValue: "2020-01-01", value: "3" },
{ dateValue: "2020-01-02", value: "4" },
{ dateValue: "2020-01-30", value: "5" },
{ dateValue: "2020-02-01", value: "6" },
{ dateValue: "2020-02-02", value: "7" },
{ dateValue: "2020-01-01", value: "3.000000000000000000" },
{ dateValue: "2020-01-02", value: "4.000000000000000000" },
{ dateValue: "2020-01-30", value: "5.000000000000000000" },
{ dateValue: "2020-02-01", value: "6.000000000000000000" },
{ dateValue: "2020-02-02", value: "7.000000000000000000" },
]);

// Deploy composed stream
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/permissions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe.sequential("Permissions", { timeout: 90000 }, () => {

// Insert test data
tx = await primitiveStream.insertRecords([
{ dateValue: "2024-01-01", value: "100" },
{ dateValue: "2024-01-01", value: "100.000000000000000000" },
]);
await waitForTxSuccess(tx, ownerClient);

Expand All @@ -54,7 +54,7 @@ describe.sequential("Permissions", { timeout: 90000 }, () => {
dateTo: "2024-01-01",
});
expect(publicRecords.length).toBe(1);
expect(publicRecords[0].value).toBe("100");
expect(publicRecords[0].value).toBe("100.000000000000000000");

// Set stream to private
tx = await primitiveStream.setReadVisibility(visibility.private);
Expand Down Expand Up @@ -128,7 +128,7 @@ describe.sequential("Permissions", { timeout: 90000 }, () => {
tx = await primitiveStream.initializeStream();
await waitForTxSuccess(tx, ownerClient);
tx = await primitiveStream.insertRecords([
{ dateValue: "2024-01-01", value: "100" },
{ dateValue: "2024-01-01", value: "100.000000000000000000" },
]);
await waitForTxSuccess(tx, ownerClient);
// Deploy and initialize composed stream
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/primitiveStream.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe.sequential(

// Verify record content
expect(records.length).toBe(1);
expect(records[0].value).toBe("1");
expect(records[0].value).toBe("1.000000000000000000");
expect(records[0].dateValue).toBe("2020-01-01");

// Query index
Expand All @@ -65,13 +65,13 @@ describe.sequential(

// Verify index content
expect(index.length).toBe(1);
expect(index[0].value).toBe("100");
expect(index[0].value).toBe("100.000000000000000000");
expect(index[0].dateValue).toBe("2020-01-01");

// Query first record
const firstRecord = await primitiveStream.getFirstRecord({});
expect(firstRecord).not.toBeNull();
expect(firstRecord?.value).toBe("1");
expect(firstRecord?.value).toBe("1.000000000000000000");
expect(firstRecord?.dateValue).toBe("2020-01-01");
} finally {
// Cleanup: destroy the stream after test
Expand Down

0 comments on commit b098f7c

Please sign in to comment.