UNPKG

@neo-one/smart-contract-compiler

Version:

NEO•ONE TypeScript smart contract compiler.

45 lines (43 loc) 1.75 kB
import { tsUtils } from '@neo-one/ts-utils'; import { BuiltinCall } from '../BuiltinCall'; export class AssertEqual extends BuiltinCall { emitCall(sb, node, optionsIn) { const options = sb.pushValueOptions(optionsIn); if (tsUtils.argumented.getArguments(node).length < 2) { return; } const received = tsUtils.argumented.getArguments(node)[0]; const expected = tsUtils.argumented.getArguments(node)[1]; sb.visit(expected, options); sb.visit(received, options); sb.emitOp(node, 'TUCK'); sb.emitOp(node, 'OVER'); sb.emitHelper(node, options, sb.helpers.if({ condition: () => { sb.emitHelper(node, options, sb.helpers.equalsEqualsEquals({ leftType: sb.context.analysis.getType(received), rightType: sb.context.analysis.getType(expected), })); }, whenTrue: () => { sb.emitOp(node, 'DROP'); sb.emitOp(node, 'DROP'); }, whenFalse: () => { sb.emitPushString(node, ' to equal '); sb.emitHelper(node, options, sb.helpers.wrapString); sb.emitOp(node, 'ROT'); sb.emitPushString(node, 'Expected '); sb.emitHelper(node, options, sb.helpers.wrapString); sb.emitPushInt(node, 4); sb.emitOp(node, 'PACK'); sb.emitHelper(node, options, sb.helpers.consoleLog); sb.emitOp(received, 'THROW'); }, })); } } export const add = (builtins) => { builtins.addTestValue('assertEqual', new AssertEqual()); }; //# sourceMappingURL=index.js.map