mirror of
https://github.com/cerc-io/watcher-ts
synced 2025-01-21 10:39:06 +00:00
toI64 debugging changes
This commit is contained in:
parent
d455a95c9f
commit
e2aa023ead
@ -41,7 +41,7 @@
|
||||
"asbuild:release": "asc assembly/index.ts --lib ./node_modules --exportRuntime --target release --runPasses asyncify",
|
||||
"asbuild": "yarn asbuild:debug && yarn asbuild:release",
|
||||
"test:init": "cp .env.example .env && yarn build:example",
|
||||
"test": "yarn asbuild:debug && DEBUG=vulcanize:* node node_modules/.bin/_mocha src/**/*.test.ts",
|
||||
"test": "DEBUG=vulcanize:* node node_modules/.bin/_mocha src/**/json.test.ts",
|
||||
"build:example": "cd test/subgraph/example1 && yarn && yarn codegen && yarn build",
|
||||
"watch": "DEBUG=vulcanize:* nodemon --watch src src/watcher.ts",
|
||||
"compare-entity": "node bin/compare-entity",
|
||||
|
@ -50,7 +50,7 @@ describe('json host api', () => {
|
||||
await testJsonFromBytes();
|
||||
});
|
||||
|
||||
it('should parse JSON safely', async () => {
|
||||
xit('should parse JSON safely', async () => {
|
||||
const { testJsonTryFromBytes } = exports;
|
||||
|
||||
await testJsonTryFromBytes();
|
||||
|
@ -515,7 +515,10 @@ export const instantiate = async (
|
||||
return isEqual;
|
||||
},
|
||||
'bigInt.fromString': async (s: number) => {
|
||||
console.log('before __getString');
|
||||
const string = __getString(s);
|
||||
console.log('string', string);
|
||||
console.log('after __getString');
|
||||
|
||||
// The BN is being stored as a byte array in wasm memory in 2's compliment representation and interpreted as such in other APIs.
|
||||
// Create a BN in 2's compliment representation.
|
||||
@ -533,6 +536,7 @@ export const instantiate = async (
|
||||
const bytes = bigNumber.toArray(BN_ENDIANNESS, bnSize);
|
||||
|
||||
const uint8ArrayId = await getIdOfType(TypeId.Uint8Array);
|
||||
console.log('before __newArray');
|
||||
const ptr = await __newArray(uint8ArrayId, bytes);
|
||||
const bigInt = await ASBigInt.fromSignedBytes(ptr);
|
||||
|
||||
@ -770,16 +774,37 @@ export const instantiate = async (
|
||||
// TODO: Number methods do not work as 64bit values are not supported in js.
|
||||
// Tried solution in https://github.com/AssemblyScript/assemblyscript/issues/117#issuecomment-531556954
|
||||
'json.toI64': async (decimal: number) => {
|
||||
return BigInt(__getString(decimal));
|
||||
console.log('decimal toI64', __getString(decimal));
|
||||
|
||||
const ptr = await __newString(__getString(decimal));
|
||||
try {
|
||||
const y = await ASBigInt.fromString(ptr);
|
||||
console.log('y', y);
|
||||
} catch (error) {
|
||||
console.log('error', error);
|
||||
}
|
||||
|
||||
return BigInt(__getString(ptr));
|
||||
},
|
||||
'json.toU64': async (decimal: number) => {
|
||||
console.log('decimal toU64', __getString(decimal));
|
||||
return BigInt(__getString(decimal));
|
||||
},
|
||||
'json.toF64': async (decimal: number) => {
|
||||
console.log('decimal toF64', __getString(decimal));
|
||||
return BigInt(__getString(decimal));
|
||||
},
|
||||
'json.toBigInt': async (decimal: number) => {
|
||||
console.log('decimal toBigInt', __getString(decimal));
|
||||
const ptr = await __newString(__getString(decimal));
|
||||
|
||||
try {
|
||||
const y = await ASBigInt.fromString(ptr);
|
||||
console.log('y', y);
|
||||
} catch (error) {
|
||||
console.log('error', error);
|
||||
}
|
||||
|
||||
return ASBigInt.fromString(ptr);
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
"deploy-local": "graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 example1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@graphprotocol/graph-ts": "npm:@cerc-io/graph-ts@0.22.1-watcher-ts-0.1.0",
|
||||
"@cerc-io/graph-cli": "0.22.4-watcher-ts-0.1.2"
|
||||
"@graphprotocol/graph-ts": "npm:@cerc-io/graph-ts@0.27.0-watcher-ts-0.1.3",
|
||||
"@cerc-io/graph-cli": "0.32.0-watcher-ts-0.1.3"
|
||||
}
|
||||
}
|
||||
|
@ -565,6 +565,7 @@ export function testJsonFromBytes (): void {
|
||||
);
|
||||
|
||||
const jsonData = json.fromBytes(data);
|
||||
log.debug('jsonData.kind {}', [jsonData.kind.toString()]);
|
||||
assert(jsonData.kind === JSONValueKind.OBJECT, 'JSON value is not an object');
|
||||
|
||||
const stringValue = jsonData.toObject().get('stringValue')!;
|
||||
@ -577,13 +578,16 @@ export function testJsonFromBytes (): void {
|
||||
const numberValue = jsonData.toObject().get('numberValue')!;
|
||||
assert(numberValue.kind === JSONValueKind.NUMBER, 'JSON value is not a number');
|
||||
|
||||
// TODO: Debug json toI64 failing test case.
|
||||
// const i64Value = numberValue.toI64();
|
||||
// assert(i64Value == 123, 'values are not equal');
|
||||
|
||||
log.debug('numberValue.kind {}', [numberValue.kind.toString()]);
|
||||
const bigIntValue = numberValue.toBigInt();
|
||||
const expectedBigInt = BigInt.fromString('123');
|
||||
assert(bigIntValue.equals(expectedBigInt), 'BigInt values are not equal');
|
||||
|
||||
// TODO: Debug json toI64 failing test case.
|
||||
log.debug('numberValue.kind {}', [numberValue.kind.toString()]);
|
||||
const i64Value = numberValue.toI64();
|
||||
log.debug('i64Value: {}', [i64Value.toString()]);
|
||||
assert(i64Value === 123, 'values are not equal');
|
||||
}
|
||||
|
||||
export function testJsonTryFromBytes (): void {
|
||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user