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

64.28% Statements 18/28
100% Branches 0/0
0% Functions 0/4
64.28% Lines 18/28

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 28 291x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x     1x 1x     1x 1x       1x 1x       1x  
import { Coder } from "./abstract-coder.js";
import type { Reader, Writer } from "./abstract-coder.js";
 
const Empty = new Uint8Array([ ]);
 
/**
 *  @_ignore
 */
export class NullCoder extends Coder {
 
    constructor(localName: string) {
        super("null", "", localName, false);
    }
 
    defaultValue(): null {
        return null;
    }
 
    encode(writer: Writer, value: any): number {
        if (value != null) { this._throwError("not null", value); }
        return writer.writeBytes(Empty);
    }
 
    decode(reader: Reader): any {
        reader.readBytes(0);
        return null;
    }
}