Skip to content

Commit 2265696

Browse files
fix: Fix tests and code
1 parent 9ec9ca7 commit 2265696

File tree

3 files changed

+6
-24
lines changed

3 files changed

+6
-24
lines changed

src/parser.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,8 @@ import {
1111
RpcClient,
1212
TypeID,
1313
} from 'casper-js-sdk';
14-
import {
15-
Event,
16-
parseEventDataFromBytes,
17-
parseEventNameWithRemainder,
18-
} from './event';
19-
import { parseSchemasFromBytes, Schemas } from './schema';
14+
import {Event, parseEventDataFromBytes, parseEventNameWithRemainder,} from './event';
15+
import {parseSchemasFromBytes, Schemas} from './schema';
2016

2117
export interface ContractMetadata {
2218
schemas: Schemas;
@@ -219,14 +215,7 @@ export class Parser {
219215
}
220216

221217
newDictionaryFromBytes(data: Uint8Array): Dictionary {
222-
const u32 = CLValueUInt32.fromBytes(data);
223-
const length = u32.result.toNumber();
224-
225-
if (!length) {
226-
throw new Error(`Invalid length for bytes: ${length}`);
227-
}
228-
229-
const clValue = CLValueParser.fromBytesWithType(u32.bytes);
218+
const clValue = CLValueParser.fromBytesWithType(data);
230219

231220
if (
232221
!(clValue.result.type instanceof CLTypeList) ||

test/parser.test.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
import * as fs from 'fs';
22
import * as path from 'path';
33

4-
import {CLTypeByteArray, Conversions, HttpHandler, InfoGetTransactionResult, RpcClient} from 'casper-js-sdk';
4+
import {Conversions, HttpHandler, InfoGetTransactionResult, RpcClient} from 'casper-js-sdk';
55
import {Parser, parseSchemasFromBytes} from '../src';
66

77
describe('Parser', () => {
88
describe('parseExecutionResult', () => {
99
it('should parse events', async () => {
10-
11-
const byteArrayType = new CLTypeByteArray(32);
12-
13-
console.log({bytes: Conversions.encodeBase16(byteArrayType.toBytes())})
14-
1510
const schemaHex =
1611
'08000000100000004164646564546f57686974656c6973740100000007000000616464726573730b0e00000042616c6c6f7443616e63656c65640500000005000000766f7465720b09000000766f74696e675f6964040b000000766f74696e675f74797065030600000063686f69636503050000007374616b65080a00000042616c6c6f74436173740500000005000000766f7465720b09000000766f74696e675f6964040b000000766f74696e675f74797065030600000063686f69636503050000007374616b65080c0000004f776e65724368616e67656401000000090000006e65775f6f776e65720b1400000052656d6f76656446726f6d57686974656c6973740100000007000000616464726573730b1300000053696d706c65566f74696e67437265617465640c0000000d000000646f63756d656e745f686173680a0700000063726561746f720b050000007374616b650d0809000000766f74696e675f69640416000000636f6e6669675f696e666f726d616c5f71756f72756d041b000000636f6e6669675f696e666f726d616c5f766f74696e675f74696d650514000000636f6e6669675f666f726d616c5f71756f72756d0419000000636f6e6669675f666f726d616c5f766f74696e675f74696d650516000000636f6e6669675f746f74616c5f6f6e626f61726465640822000000636f6e6669675f646f75626c655f74696d655f6265747765656e5f766f74696e6773001d000000636f6e6669675f766f74696e675f636c6561726e6573735f64656c7461082e000000636f6e6669675f74696d655f6265747765656e5f696e666f726d616c5f616e645f666f726d616c5f766f74696e67050e000000566f74696e6743616e63656c65640300000009000000766f74696e675f6964040b000000766f74696e675f747970650308000000756e7374616b6573110b080b000000566f74696e67456e6465640d00000009000000766f74696e675f6964040b000000766f74696e675f74797065030d000000766f74696e675f726573756c74030e0000007374616b655f696e5f6661766f72080d0000007374616b655f616761696e73740816000000756e626f756e645f7374616b655f696e5f6661766f720815000000756e626f756e645f7374616b655f616761696e7374080e000000766f7465735f696e5f6661766f72040d000000766f7465735f616761696e73740408000000756e7374616b657311130b0408060000007374616b657311130b0408050000006275726e7311130b0408050000006d696e747311130b0408';
1712

@@ -57,8 +52,6 @@ describe('Parser', () => {
5752

5853
const transactionResult = InfoGetTransactionResult.fromJSON(rawMintDeploy);
5954

60-
61-
6255
const events = parser.parseExecutionResult(
6356
transactionResult!.executionInfo!.executionResult,
6457
);

test/schema.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ describe('Schema', () => {
5353
expect(schema.result[0].value.getTypeID()).toEqual(TypeID.ByteArray);
5454

5555
expect(schema.result[1].property).toEqual('token_id');
56-
expect(schema.result[1].value.getTypeID()).toEqual(TypeID.ByteArray);
56+
expect(schema.result[1].value.getTypeID()).toEqual(TypeID.U256);
5757

5858
expect(schema.result[2].property).toEqual('offerer');
59-
expect(schema.result[2].value.getTypeID()).toEqual(TypeID.ByteArray);
59+
expect(schema.result[2].value.getTypeID()).toEqual(TypeID.Key);
6060
});
6161
});
6262
});

0 commit comments

Comments
 (0)