github.com/hyperledger/burrow@v0.34.5-0.20220512172541-77f09336001d/js/src/test/handler-overwriting.test.ts (about) 1 import * as assert from 'assert'; 2 import { CallResult } from '../contracts/call'; 3 import { compile } from '../contracts/compile'; 4 import { getMetadata } from '../contracts/contract'; 5 import { withoutArrayElements } from '../convert'; 6 import { client } from './test'; 7 8 describe('Testing Per-contract handler overwriting', function () { 9 // {handlers: {call: function (result) { return {super: result.values, man: result.raw} }}}) 10 11 it('#17 Testing Per-contract handler overwriting', async () => { 12 const source = ` 13 pragma solidity >=0.0.0; 14 contract Test { 15 16 function getAddress() public view returns (address) { 17 return address(this); 18 } 19 20 function getNumber() public pure returns (uint) { 21 return 100; 22 } 23 24 function getCombination() public view returns (uint _number, address _address, string memory _saying, bytes32 _randomBytes) { 25 _number = 100; 26 _address = address(this); 27 _saying = "hello moto"; 28 _randomBytes = bytes32(uint256(0xDEADBEEFFEEDFACE)); 29 } 30 31 } 32 `; 33 34 const instance: any = await compile(source, 'Test').deployWith(client, { 35 handler: function ({ result }: CallResult) { 36 return { 37 values: withoutArrayElements(result), 38 raw: [...result], 39 }; 40 }, 41 }); 42 const address = getMetadata(instance).address; 43 const returnObject = await instance.getCombination(); 44 const randomBytes = Buffer.from('000000000000000000000000000000000000000000000000DEADBEEFFEEDFACE', 'hex'); 45 const expected = { 46 values: { 47 _number: 100, 48 _address: address, 49 _saying: 'hello moto', 50 _randomBytes: randomBytes, 51 }, 52 raw: [100, address, 'hello moto', randomBytes], 53 }; 54 assert.deepStrictEqual(returnObject, expected); 55 }); 56 });