All files / ethers.js/src.ts/abi/coders boolean.ts

92.59% Statements 25/27
100% Branches 5/5
75% Functions 3/4
92.59% Lines 25/27

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 281x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1518x 1518x 1x 1x     1x 1x 1841x 1841x 1841x 1x 1x 1845x 1845x 1x  
import { Typed } from "../typed.js";
import { Coder } from "./abstract-coder.js";
 
import type { Reader, Writer } from "./abstract-coder.js";
 
/**
 *  @_ignore
 */
export class BooleanCoder extends Coder {
 
    constructor(localName: string) {
        super("bool", "bool", localName, false);
    }
 
    defaultValue(): boolean {
        return false;
    }
 
    encode(writer: Writer, _value: boolean | Typed): number {
        const value = Typed.dereference(_value, "bool");
        return writer.writeValue(value ? 1: 0);
    }
 
    decode(reader: Reader): any {
        return !!reader.readValue();
    }
}