Options
All
  • Public
  • Public/Protected
  • All
Menu

Index

Variables

METADATA_SPACE: object_space = ...

Functions

  • clearLogs(): void
  • Remove the current logs

    example
    System.log('log 1');
    System.log('log 2');
    MockVM.clearLogs();
    System.log('log 3');
    System.log('log 4');
    console.log(MockVM.getLogs().join(","));
    // log 3,log 4

    Returns void

  • commitTransaction(): void
  • Backup the database so that it can be rolledback to the backedup state if the transaction reverts

    example
    MockVM.commitTransaction();
    

    Returns void

  • getContractResult(): Uint8Array | null
  • Get contract result set when calling System.exit()

    example
    System.setContractResult(Base64.decode('res1'));

    const contractRes = MockVM.getContractResult();

    if (contractRes) {
    System.log('contractRes: ' + (Base64.encode(contractRes as Uint8Array) as string));
    }

    Returns Uint8Array | null

  • getErrorMessage(): String | null
  • Get error message string after a VM error

    example
    const errorMessage = MockVM.getErrorMessage();
    

    Returns String | null

  • Get logs set when calling System.log()

    example
    System.Event('my-event-1', Base64.decode('event data'), [Base58.decode('1DQzuCcTKacbs9GGScRTU1Hc8BsyARTPqe')]);
    System.Event('my-event-2', Base64.decode('event data 2'), [Base58.decode('1DQzuCcTKacbs9GGScRTU1Hc8BsyARTPqe')]);

    const events = MockVM.getEvents();

    for (let index = 0; index < events.length; index++) {
    const event = events[index];

    System.log(event.name)
    System.log(event.data.toString())

    event.impacted.forEach(acct => {
    System.log(Base58.encode(acct));
    });
    }

    Returns event_arguments[]

  • getExitCode(): i32
  • Get exit code set when calling System.exitContract(...)

    example
    System.exit(0);

    const exitCode = MockVM.getExitCode();

    if (exitCode) {
    System.log('exitCode: ' + exitCode.toString());
    }

    Returns i32

  • getLogs(): string[]
  • Get logs set when calling System.log()

    example
    System.log('log 1');
    System.log('log 2');

    const logs = MockVM.getLogs();

    for (let index = 0; index < logs.length; index++) {
    const log = logs;
    }

    Returns string[]

  • reset(): void
  • rollbackTransaction(): void
  • Rrestore the backup made via MockVM.commitTransaction()

    example
    MockVM.rollbackTransaction();
    

    Returns void

  • Set authorities that will be used when calling System.requireAuthority(...)

    example
    const account = Base58.decode('1DQzuCcTKacbs9GGScRTU1Hc8BsyARTPqe');
    const auth1 = new MockVM.MockAuthority(authority.authorization_type.contract_call, account, true);
    const auth2 = new MockVM.MockAuthority(authority.authorization_type.contract_upload, account, false)

    MockVM.setAuthorities([auth1, auth2]);

    System.requireAuthority(authority.authorization_type.contract_call, account);

    Parameters

    Returns void

  • setBlock(block: block): void
  • Set block that will be used when calling System.getBlock() and System.getBlockField(...)

    example
    let block = new protocol.block();
    block.id = StringBytes.stringToBytes("0x12345");

    MockVM.setBlock(block);

    block = System.getBlock();

    System.log("block.id: " + (StringBytes.bytesToString((block.id) as Uint8Array) as string));

    let blField = System.getBlockField('id');
    if (blField) {
    System.log("block.id: " + (StringBytes.bytesToString((blField.bytes_value) as Uint8Array) as string));
    }

    Parameters

    • block: block

      block to set

    Returns void

  • Set call contract results that will be used when calling System.callContract(...)

    example
    const callContractResults = new value.list_type();

    const callContractRes1 = Base64.decode('res1');
    const callContractRes2 = Base64.decode('res2');

    MockVM.setCallContractResults([callContractRes1, callContractRes2]);

    let callRes = System.callContract(contract_id, 1, new Uint8Array(0));
    if (callRes) {
    System.log('callRes1: ' + (Base64.encode(callRes as Uint8Array) as string));
    }

    callRes = System.callContract(contract_id, 1, new Uint8Array(0));
    if (callRes) {
    System.log('callRes2: ' + (Base64.encode(callRes as Uint8Array) as string));
    }

    Parameters

    • callContractResults: exit_arguments[]

      The results are FIFO, so the first System.callContract(...) used in your code will use the first result you set in callContractResults, the second System.callContract(...) will get the second result, etc...

    Returns void

  • Set caller data that will be used when calling System.getCaller()

    example
    let callerData = new chain.caller_data(Base58.decode('1DQzuCcTKacbs9GGScRTU1Hc8BsyARTPqe'), chain.privilege.user_mode);

    MockVM.setCaller(callerData);

    callerData = System.getCaller();

    System.log('callerData.caller_privilege: ' + callerData.caller_privilege.toString());
    if (callerData.caller) {
    System.log('callerData.caller (b58): ' + Base58.encode(callerData.caller!));
    }

    Parameters

    Returns void

  • setChainId(chainId: Uint8Array): void
  • setContractArguments(contractArguments: Uint8Array): void
  • Set contract arguments that will be used when calling System.getContractArguments()

    example
    let contractArguments = StringBytes.stringToBytes('myArgs');
    MockVM.setContractArguments(contractArguments);

    contractArguments = System.getContractArguments();
    System.log('contractArguments: ' + (StringBytes.bytesToString(contractArguments)!));

    Parameters

    • contractArguments: Uint8Array

      contract arguments to set

    Returns void

  • setContractId(contractId: Uint8Array): void
  • Set contract id that will be used when calling System.getContractArguments()

    example
    let contractId = Base58.decode('1DQzuCcTKacbs9GGScRTU1Hc8BsyARTPqe');
    MockVM.setContractId(contractId);

    contractId = System.getContractId();
    System.log('contractId: ' + Base58.encode(contractId));

    Parameters

    • contractId: Uint8Array

      contract id to set

    Returns void

  • setEntryPoint(entryPoint: number): void
  • Set entry point that will be used when calling System.getEntryPoint()

    example
    MockVM.setEntryPoint(0xc3ab8ff1);

    const entryPoint = System.getEntryPoint();
    System.log('entryPoint: ' + entryPoint.toString());

    Parameters

    • entryPoint: number

      entry point to set

    Returns void

  • Set head info that will be used when calling System.getHeadInfo()

    example
    let headInfo = new chain.head_info();
    headInfo.head_block_time = 123456789;
    headInfo.last_irreversible_block = 3;

    MockVM.setHeadInfo(headInfo);

    headInfo = System.getHeadInfo();
    System.log('headInfo.head_block_time: ' + headInfo.head_block_time.toString());

    Parameters

    Returns void

  • setLastIrreversibleBlock(lastIrreversibleBlock: number): void
  • Set entry point that will be used when calling System.getEntryPoint()

    example
    MockVM.setLastIrreversibleBlock(987654321);

    const lastIrreversibleBlock = System.getLastIrreversibleBlock();
    System.log('lastIrreversibleBlock: ' + lastIrreversibleBlock.toString());

    Parameters

    • lastIrreversibleBlock: number

      last irreversible block height to set

    Returns void

  • Set operation that will be used when calling System.getOperation()

    example
    let setOperation = new protocol.operation();
    setOperation.set_system_contract = new protocol.set_system_contract_operation(Base58.decode('1DQzuCcTKacbs9GGScRTU1Hc8BsyARTPqe'), true);

    MockVM.setOperation(setOperation);

    const getOperation = System.getOperation();
    ...

    Parameters

    Returns void

  • setSystemAuthority(authorized: bool): void
  • Set system authority that will be used when calling System.requireSystemAuthority(...)

    Parameters

    • authorized: bool
      MockVM.setSystemAuthority(true);

      System.requireSystemAuthority();

    Returns void

  • Set transaction that will be used when calling System.getTransaction() and System.getTransactionField(...)

    example
    let transaction = new protocol.transaction();
    transaction.id = StringBytes.stringToBytes("0x12345");

    MockVM.setTransaction(transaction);

    transaction = System.getTransaction();

    System.log("transaction.id: " + (StringBytes.bytesToString((transaction.id)!)!));

    let txField = System.getTransactionField('id');
    if (txField) {
    System.log("transaction.id: " + (StringBytes.bytesToString((txField.bytes_value) as Uint8Array) as string));
    }

    Parameters

    Returns void

  • setVerifyVRFProofResults(verifyVRFProofResults: bool[]): void
  • Set results that will be used when calling System.verifyVRFProof(...)

    example
    MockVM.setVerifyVRFProofResults([false, true]);

    let callRes = System.verifyVRFProof(pubKey, proof, hash, messgae);
    if (callRes) {
    // Will execute
    }

    let callRes = System.verifyVRFProof(pubKey, proof, hash, messgae);
    if (callRes) {
    // Will not execute
    }

    Parameters

    • verifyVRFProofResults: bool[]

      The results are FIFO, so the first System.verifyVRFPRoof(...) used in your code will use the first result you set in callContractResults, the second System.callContract(...) will get the second result, etc...

    Returns void

Generated using TypeDoc