watcher-ts/packages/graph-node/src/numbers.test.ts
Ashwin Phatak bf54e85d05 eth_call and invoking event handler in WASM (#25)
* Perform eth_call and get result in js import

* Use dummy value for eth_call

* Called handler in wasm with event param

* Implement passing event to subgraph handler function

* Use generated event class Test for passing to handler

* Pass event params to handler

Co-authored-by: nabarun <nabarun@deepstacksoft.com>
2021-12-28 16:08:05 +05:30

55 lines
1.6 KiB
TypeScript

//
// Copyright 2021 Vulcanize, Inc.
//
import path from 'path';
import { expect } from 'chai';
import { instantiate } from './index';
const EXAMPLE_WASM_FILE_PATH = '../test/subgraph/example1/build/Example1/Example1.wasm';
describe('numbers wasm tests', () => {
let exports: any;
before(async () => {
const filePath = path.resolve(__dirname, EXAMPLE_WASM_FILE_PATH);
const instance = await instantiate(filePath);
exports = instance.exports;
const { _start } = exports;
// Important to call _start for built subgraphs on instantiation!
// TODO: Check api version https://github.com/graphprotocol/graph-node/blob/6098daa8955bdfac597cec87080af5449807e874/runtime/wasm/src/module/mod.rs#L533
_start();
});
it('should execute bigInt fromString API', () => {
const { testBigIntFromString, __getString } = exports;
const ptr = testBigIntFromString();
expect(__getString(ptr)).to.equal('123');
});
it('should execute bigInt plus API', () => {
const { testBigIntPlus, __getString } = exports;
const ptr = testBigIntPlus();
expect(__getString(ptr)).to.equal('200');
});
it('should execute bigInt minus API', () => {
const { testBigIntMinus, __getString } = exports;
const ptr = testBigIntMinus();
expect(__getString(ptr)).to.equal('100');
});
xit('should execute bigDecimal dividedBy API', () => {
const { testBigDecimalDividedBy, __getString } = exports;
const ptr = testBigDecimalDividedBy();
expect(__getString(ptr)).to.equal('10000000000000000');
console.log(__getString(ptr));
});
});