The Klayr SDK testing utilities

Fixtures

defaultFaucetAccount

Returns a default faucet account.

Usage

const sdk = require('klayr-sdk');

sdk.testing.fixtures.defaultFaucetAccount
Returns
{
  address: <Buffer d0 46 99 e5 7c 4a 38 46 c9 88 f3 c1 53 06 79 6f 8e ae 5c 1c>,
  publicKey: <Buffer 0f e9 a3 f1 a2 1b 55 30 f2 7f 87 a4 14 b5 49 e7 9a 94 0b f2 4f df 2b 2f 05 e7 f2 2a ee ec c8 6a>,
  passphrase: 'peanut hundred pen hawk invite exclude brain chunk gadget wait wrong ready',
  balance: '10000000000000000',
  encryptedPassphrase: 'iterations=10&cipherText=6541c04d7a46eacd666c07fbf030fef32c5db324466e3422e59818317ac5d15cfffb80c5f1e2589eaa6da4f8d611a94cba92eee86722fc0a4015a37cff43a5a699601121fbfec11ea022&iv=141edfe6da3a9917a42004be&salt=f523bba8316c45246c6ffa848b806188&tag=4ffb5c753d4a1dc96364c4a54865521a&version=1',
  password: 'elephant tree paris dragon chair galaxy'
}

defaultAccounts

Returns a list of all addresses of the 103 genesis delegates.

Usage

const sdk = require('klayr-sdk');

sdk.testing.fixtures.defaultAccounts()
Returns
[
  {
    address: <Buffer 9c ab ee 3d 27 42 66 76 b8 52 ce 6b 80 4c b2 fd ff 7c d0 b5>
  },
  {
    address: <Buffer 46 3e 7e 87 9b 7b dc 6a 97 ec 02 a2 a6 03 aa 1a 46 a0 4c 80>
  },
  {
    address: <Buffer 32 8d 0f 54 66 95 c5 fa 02 10 5d eb 05 5c f2 80 1d 9b 8b a1>
  },
  // +100 more
]

createDefaultAccount

Generates account data for a user account.

Parameters

  1. modules(array): List of modules. The modules account schemas will be included in the returned account.

  2. data(object): Custom account data.

Usage

const sdk = require('klayr-sdk');

sdk.testing.fixtures.createDefaultAccount([sdk.TokenModule, sdk.DPoSModule], {customKey:"someData"});
Returns
{
  token: { balance: 0n },
  dpos: {
    delegate: {
      username: '',
      pomHeights: [],
      consecutiveMissedBlocks: 0,
      lastForgedHeight: 0,
      isBanned: false,
      totalVotesReceived: 0n
    },
    sentVotes: [],
    unlocking: []
  },
  customKey: 'someData',
  address: <Buffer 43 04 e6 71 08 7f 40 ff bc 30 29 ad 2e f7 16 ad 5c 00 5e 7f>
}

defaultPassword

Returns a default password.

Usage

const sdk = require('klayr-sdk');

sdk.testing.fixtures.defaultPassword
Returns
'elephant tree paris dragon chair galaxy'

defaultConfig

A default configuration for a blockchain application.

Usage

const sdk = require('klayr-sdk');

sdk.testing.fixtures.defaultConfig
Returns
{
  label: 'beta-sdk-app',
  version: '0.0.0',
  networkVersion: '1.0',
  rootPath: '~/.klayr',
  logger: {
    fileLogLevel: 'none',
    consoleLogLevel: 'none',
    logFileName: 'klayr.log'
  },
  genesisConfig: {
    blockTime: 10,
    communityIdentifier: 'sdk',
    maxPayloadLength: 15360,
    bftThreshold: 68,
    minFeePerByte: 1000,
    baseFees: [ [Object] ],
    rewards: { milestones: [Array], offset: 2160, distance: 3000000 },
    minRemainingBalance: '5000000',
    activeDelegates: 101,
    standbyDelegates: 2,
    delegateListRoundOffset: 2
  },
  forging: {
    force: true,
    waitThreshold: 2,
    delegates: [
      {
        encryptedPassphrase: 'iterations=10&cipherText=c6eb47b7588d578602850c7c3d657515ce9c3b15f0d8335803f08825176e3fcf3da69b76af81c9b819902772f6e7738ad5ec9184589d4af43cf808130205f7560b4b1b151be74221846013fe&iv=3b4b5b901edb52521f78f0bf&salt=c2dbd7ee2ba11ae9ad20c1ffe44a8460&tag=e51a1770bae9a93af5c0f2fcd4579061&version=1',
        hashOnion: {
            count: 10000,
            distance: 1000,
            hashes: [
                '8903ea6e67ccd67bafa1c9c04184a387',
                '719142332e71b58d2cfd24aeabef0666',
                '02dcf8bd4e8427aaa0ef9af8ff903015',
                '3c2b51970af795a5d584342c603daef3',
                '208a25f33cd3f6979983228b181118f3',
                'eb67f12d52d3726628ecfb539517ea46',
                'c89a3f3edd3661436fe1150e5c2f77cf',
                'dc3636677cac81c2720187aad64d186f',
                '5465dd9c1e107d0397aa93a5e607e908',
                '1b0fa3ed0491078e5be78528687f7b14',
                '7cab3ad7089480de104c2d4b3fe58be0'
            ]
        },
            address: '463e7e879b7bdc6a97ec02a2a603aa1a46a04c80'
        },
        ... 102 more items
    ],
    defaultPassword: 'elephant tree paris dragon chair galaxy'
  },
  network: { seedPeers: [ [Object] ], port: 5000, maxInboundConnection: 0 },
  transactionPool: {
    maxTransactions: 4096,
    maxTransactionsPerAccount: 64,
    transactionExpiryTime: 10800000,
    minEntranceFeePriority: '0',
    minReplacementFeeDifference: '10'
  },
  plugins: {},
  rpc: { enable: true, port: 8080, mode: 'ipc' }
}

getPassphraseFromDefaultConfig

Returns the passphrase of a default account.

Parameters

  • address(Buffer): The address of a default delegate.

Usage

const sdk = require('klayr-sdk');
const address = sdk.testing.fixtures.defaultAccounts()[0].address;

sdk.testing.fixtures.getPassphraseFromDefaultConfig(address)
Returns
'endless focus guilt bronze hold economy bulk parent soon tower cement venue'

getHashOnionFromDefaultConfig

Returns the hash onion for a default delegate.

Parameters

  1. address(Buffer): The address of a default delegate.

  2. count(number).

Usage

const sdk = require('klayr-sdk');
const address = sdk.testing.fixtures.defaultAccounts()[0].address;

sdk.testing.fixtures.getHashOnionFromDefaultConfig(address, 3);
Returns
<Buffer 54 9f b5 3b 1b 8a 49 d7 62 90 1e 75 4b 5c 10 24>

Mocks

StateStoreMock

Returns a mock for the state store.

View the full implementation of the StateStoreMock on GitHub.

Parameters

  • MockInput(object): Input data for the state store mock, (this is optional).

MockInput
{
	accounts?: Account<any>[];
	defaultAccount?: AccountDefaultProps;
	chain?: { [key: string]: Buffer };
	consensus?: { [key: string]: Buffer };
	lastBlockHeaders?: Partial<BlockHeader>[];
	networkIdentifier?: Buffer;
	lastBlockReward?: bigint;
}

Usage

const sdk = require('klayr-sdk');

const account = sdk.testing.fixtures.createDefaultAccount([sdk.TokenModule, sdk.DPoSModule]);

const stateStore = new sdk.testing.mocks.StateStoreMock({
    accounts: [account],
});

channelMock

Returns a mock for the channel.

Usage

const sdk = require('klayr-sdk');

sdk.testing.mocks.channelMock;
Returns
{
  publish: [Function: publish],
  registerToBus: [AsyncFunction: registerToBus],
  isValidEventName: [Function: isValidEventName],
  isValidActionName: [Function: isValidActionName],
  eventsList: [],
  actionsList: [],
  actions: {},
  moduleAlias: '',
  options: {},
  once: [Function: once],
  subscribe: [Function: subscribe],
  invoke: [AsyncFunction: invoke]
}

consensusMock

Returns a mock for consensus functions.

Usage

const sdk = require('klayr-sdk');

sdk.testing.mocks.consensusMock;
Returns
{
  getDelegates: [AsyncFunction: getDelegates],
  updateDelegates: [AsyncFunction: updateDelegates],
  getFinalizedHeight: [Function: getFinalizedHeight]
}

DataAccessMock

Returns a mock for the data access.

Parameters

  • opts(object): Input data for the data access mock, (this is optional).

{
    blockHeaders?: BlockHeader<T2>[];
    accounts?: Account<T1>[];
    chainState?: Record<string, Buffer>;
}

Usage

const sdk = require('klayr-sdk');

const dataAccess = new sdk.testing.mocks.DataAccessMock()

loggerMock

Returns a mock of the logger.

Usage

const sdk = require('klayr-sdk');

sdk.testing.mocks.loggerMock;
Returns
{
  trace: [Function: trace],
  debug: [Function: debug],
  info: [Function: info],
  warn: [Function: warn],
  error: [Function: error],
  fatal: [Function: fatal],
  level: [Function: level]
}

reducerHandlerMock

Returns a mock for the reducer handler.

Usage

const sdk = require('klayr-sdk');

sdk.testing.mocks.reducerHandlerMock;
Returns
{ invoke: [AsyncFunction: invoke] }

Functions

getBlockProcessingEnv

Used for integration testing.

Parameters

{
	modules?: ModuleClass[];
	options?: Options;
	accounts?: PartialAccount<T>[];
	initDelegates?: Buffer[];
}

Usage

const sdk = require('klayr-sdk');

await sdk.testing.getBlockProcessingEnv({})
Returns
BlockProcessingEnv
{
	createBlock: (payload?: Transaction[], timestamp?: number) => Promise<Block>;
	getProcessor: () => Processor;
	getChain: () => Chain;
	getBlockchainDB: () => KVStore;
	process: (block: Block) => Promise<void>;
	processUntilHeight: (height: number) => Promise<void>;
	getLastBlock: () => Block;
	getValidators: () => Promise<Validator[]>;
	getNextValidatorPassphrase: (blockHeader: BlockHeader) => Promise<string>;
	getDataAccess: () => DataAccess;
	getNetworkId: () => Buffer;
	cleanup: (config: Options) => Promise<void>;
}

createDefaultApplicationEnv

Used for functional testing.

View the full implementation of the ApplicationEnv on GitHub.

Parameters

  • appConfig(object): Environment variables for the application.

ApplicationEnvConfig
{
	modules: ModuleClass[];
	plugins?: InstantiablePlugin[];
	config?: PartialApplicationConfig;
	genesisBlockJSON?: Record<string, unknown>;
}

Usage

const sdk = require('klayr-sdk');

sdk.testing.createDefaultApplicationEnv([sdk.TokenModule,sdk.DPoSModule])
Returns
ApplicationEnv {
  _dataPath: '~/.klayr/beta-sdk-app',
  _application: Application {
    _mutex: Mutex { _queue: [], _locked: false },
    _genesisBlock: { header: [Object], payload: [] },
    config: {
      label: 'beta-sdk-app',
      version: '0.0.0',
      networkVersion: '1.0',
      rootPath: '~/.klayr',
      logger: [Object],
      rpc: [Object],
      genesisConfig: [Object],
      forging: [Object],
      network: [Object],
      transactionPool: [Object],
      plugins: {}
    },
    _plugins: {},
    _node: Node {
      _registeredModules: [Array],
      _registeredAccountSchemas: [Object],
      _options: [Object],
      _genesisBlockJSON: [Object]
    }
  }
}

createTransaction

Parameters

{
	moduleID: number;
	assetClass: AssetClass;
	asset: Record<string, unknown>;
	nonce?: bigint;
	fee?: bigint;
	passphrase?: string;
	networkIdentifier?: Buffer;
}

Usage

sdk.testing.createTransaction({
    moduleID: 2,
    assetClass: TransferAsset,
    asset: {
        amount: BigInt('100000000'),
        recipientAddress: Buffer.from('8f5685bf5dcb8c1d3b9bbc98cffb0d0c6077be17', 'hex'),
        data: 'moon',
    },
    nonce: BigInt(0),
    fee: BigInt('10000000'),
    passphrase: 'wear protect skill sentence lift enter wild sting lottery power floor neglect',
    networkIdentifier: Buffer.from(
        'e48feb88db5b5cf5ad71d93cdcd1d879b6d5ed187a36b0002cc34e0ef9883255',
        'hex',
    ),
})
Returns
Transaction {
  moduleID: 2,
  assetID: 0,
  asset: <Buffer 08 80 c2 d7 2f 12 14 8f 56 85 bf 5d cb 8c 1d 3b 9b bc 98 cf fb 0d 0c 60 77 be 17 1a 04 6d 6f 6f 6e>,
  nonce: 0n,
  fee: 10000000n,
  senderPublicKey: <Buffer ef af 1d 97 78 97 cb 60 d7 db 9d 30 e8 fd 66 8d ee 07 0a c0 db 1f b8 d1 84 c0 61 52 a8 b7 5f 8d>,
  signatures: [
    <Buffer 22 21 b5 81 fe 04 44 d8 cc d4 9d 60 a5 81 92 28 9e 05 f1 88 09 5f 20 46 9f 88 4d ee ef b3 f4 23 40 10 16 d3 0a f9 06 f6 8e 69 22 3e 90 9e df 74 8f 20 ... 14 more bytes>
  ]
}

createGenesisBlock

Parameters

{
	modules: ModuleClass[];
	accounts?: PartialAccount<T>[];
	genesisConfig?: GenesisConfig;
	initDelegates?: ReadonlyArray<Buffer>;
	height?: number;
	initRounds?: number;
	timestamp?: number;
	previousBlockID?: Buffer;
}

Usage

const sdk = require('klayr-sdk');

sdk.testing.createGenesisBlock({modules: [sdk.TokenModule,sdk.DPoSModule]})
Returns
{
  genesisBlock: {
    header: {
      generatorPublicKey: <Buffer >,
      height: 0,
      previousBlockID: <Buffer >,
      reward: 0n,
      signature: <Buffer >,
      timestamp: 1623141612,
      transactionRoot: <Buffer e3 b0 c4 42 98 fc 1c 14 9a fb f4 c8 99 6f b9 24 27 ae 41 e4 64 9b 93 4c a4 95 99 1b 78 52 b8 55>,
      version: 0,
      asset: [Object],
      id: <Buffer db 62 54 2e 6f 5d db 51 24 f8 8d 24 45 a8 c0 03 90 ba 80 21 56 7f cc 76 6e ff d0 e8 9b c0 d5 ed>
    },
    payload: []
  },
  genesisBlockJSON: {
    header: {
      generatorPublicKey: '',
      height: 0,
      previousBlockID: '',
      reward: '0',
      signature: '',
      timestamp: 1623141612,
      transactionRoot: 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855',
      version: 0,
      asset: [Object],
      id: 'db62542e6f5ddb5124f88d2445a8c00390ba8021567fcc766effd0e89bc0d5ed'
    },
    payload: []
  }
}

getModuleInstance

Parameters

Module: ModuleClass<T1>,
opts?: {
    genesisConfig?: GenesisConfig;
    dataAccess?: BaseModuleDataAccess;
    channel?: BaseModuleChannel;
    logger?: Logger;
}

Usage

const sdk = require('klayr-sdk');

sdk.testing.getModuleInstance(TokenModule);
Returns
TokenModule {
  transactionAssets: [
    TransferAsset {
      name: 'transfer',
      id: 0,
      schema: [Object],
      _minRemainingBalance: 5000000n
    }
  ],
  reducers: {
    credit: [AsyncFunction: credit],
    debit: [AsyncFunction: debit],
    getBalance: [AsyncFunction: getBalance],
    getMinRemainingBalance: [AsyncFunction: getMinRemainingBalance]
  },
  actions: {},
  events: [],
  config: {},
  name: 'token',
  id: 2,
  accountSchema: {
    type: 'object',
    properties: { balance: [Object] },
    default: { balance: 0n }
  },
  _minRemainingBalance: 5000000n,
  _channel: {
    publish: [Function: publish],
    registerToBus: [AsyncFunction: registerToBus],
    isValidEventName: [Function: isValidEventName],
    isValidActionName: [Function: isValidActionName],
    eventsList: [],
    actionsList: [],
    actions: {},
    moduleAlias: '',
    options: {},
    once: [Function: once],
    subscribe: [Function: subscribe],
    invoke: [AsyncFunction: invoke]
  },
  _dataAccess: DataAccessMock {
    _blockHeaders: [],
    _chainState: {},
    _accounts: BufferMap { _data: {} }
  },
  _logger: {
    trace: [Function: trace],
    debug: [Function: debug],
    info: [Function: info],
    warn: [Function: warn],
    error: [Function: error],
    fatal: [Function: fatal],
    level: [Function: level]
  }
}

getAccountSchemaFromModules

Parameters

modules: ModuleClass[],
genesisConfig?: GenesisConfig,

Usage

const sdk = require('klayr-sdk');

sdk.testing.getAccountSchemaFromModules([sdk.TokenModule])
Returns
{
  token: {
    type: 'object',
    properties: { balance: [Object] },
    default: { balance: 0n },
    fieldNumber: 2
  }
}

createBlock

Parameters

{
	passphrase: string;
	networkIdentifier: Buffer;
	timestamp: number;
	previousBlockID: Buffer;
	payload?: Transaction[];
	header?: Partial<BlockHeader<T>>;
}

Usage

const sdk = require('klayr-sdk');

sdk.testing.createBlock({
    passphrase: sdk.testing.fixtures.defaultPassword,
    networkIdentifier: Buffer.from(
        'e48feb88db5b5cf5ad71d93cdcd1d879b6d5ed187a36b0002cc34e0ef9883255',
        'hex',
    ),
    timestamp: 0,
    previousBlockID: sdk.testing.createFakeBlockHeader().id,
    payload: [],
});
Returns
{
  header: {
    version: 2,
    timestamp: 0,
    height: 1,
    previousBlockID: <Buffer 1a 7d f6 0d fe 6b 43 cc 63 12 87 8b fa ac 4a b5 29 a5 41 29 ef c5 cc 40 28 91 dc 05 27 81 0e 0c>,
    transactionRoot: <Buffer e3 b0 c4 42 98 fc 1c 14 9a fb f4 c8 99 6f b9 24 27 ae 41 e4 64 9b 93 4c a4 95 99 1b 78 52 b8 55>,
    generatorPublicKey: <Buffer a5 ed 2b cf 19 96 36 84 e2 12 81 6d 4b 9c 26 44 64 3b 07 1f 31 84 81 ea 8a e2 c1 20 ce 02 e6 cd>,
    reward: 0n,
    asset: {
      maxHeightPreviouslyForged: 0,
      maxHeightPrevoted: 0,
      seedReveal: <Buffer 41 50 88 31 41 bd dd 0c a8 d5 ae 5e 33 57 c4 59>
    },
    signature: <Buffer d0 fe bc 59 6f 63 54 b5 93 2c 02 f0 f6 b0 88 eb 37 a1 8d 58 75 7d 2e 47 f7 ed 33 46 4b 56 c3 e9 e8 e1 f5 61 b8 ae be 8b e7 ca 6e 89 7a 63 f8 16 de e7 ... 14 more bytes>,
    id: <Buffer b0 32 8a ef 62 fa 64 92 ad c7 ed 39 f1 56 ce d0 da 4b 4f 41 2a 8a 61 82 77 6a d8 8b f1 93 9a 24>
  },
  payload: []
}

encodeBlockHeader

Parameters

  • header: Block header.

  • skipSignature(boolean): signature will be skipped if set to true, (this is optional).

Usage

let header = sdk.testing.createBlockHeaderWithDefaults()

sdk.testing.encodeBlockHeader(header)
Returns
<Buffer 08 02 10 00 18 01 22 20 15 84 a7 11 57 a4 45 50 31 a7 6b 0e 2c 03 77 03 9c 08 c9 3f 7e b9 1c ee a4 4f dd 76 69 0a b8 7b 2a 20 c5 4a 85 d9 88 80 94 df ... 84 more bytes>

createBlockHeaderWithDefaults

Creates a default block header.

Parameters

  • header: Block header partial, (this is optional).

Usage

const sdk = require('klayr-sdk');

sdk.testing.createBlockHeaderWithDefaults()
Returns
{
  version: 2,
  timestamp: 0,
  height: 1,
  previousBlockID: <Buffer e1 c3 60 bd e1 5e 33 92 91 cd cb 67 17 92 5f 16 22 f0 e5 28 3b ba a3 6b ea 29 28 a8 4e bb a2 6a>,
  transactionRoot: <Buffer 5e 6b 87 f3 b3 c2 e5 70 7f cb a6 cf 2e 11 6f f4 bb 81 33 ea 66 93 cc 09 4c 6f a9 ea 51 82 75 96>,
  generatorPublicKey: <Buffer 47 83 ad b0 21 0b 22 69 ec 44 47 54 91 1a 82 36 62 12 36 79 dc c7 34 34 b0 b0 9e f1 7e 39 25 c8>,
  reward: 0n,
  asset: {
    maxHeightPreviouslyForged: 0,
    maxHeightPrevoted: 0,
    seedReveal: <Buffer bd 4d c5 f2 7a ee 9a e3 10 eb 40 87 e9 3b 79 83>
  }
}

createFakeBlockHeader

Creates a block header with a fake signature and ID.

Parameters

  • header: Block header partial, (this is optional).

Usage

const sdk = require('klayr-sdk');

sdk.testing.createFakeBlockHeader()
Returns
{
  version: 2,
  timestamp: 0,
  height: 1,
  previousBlockID: <Buffer c7 ed 6d 76 4f 52 a5 0e 47 be 17 5b 60 aa 1e 33 04 a6 a8 32 44 19 6f 5e 42 89 be 0e 46 c8 92 f4>,
  transactionRoot: <Buffer 7e f8 74 6e 2d e3 15 0e a9 07 f2 f5 66 c4 53 e9 c7 3c f8 04 c2 58 7a 87 14 55 ea 35 02 0d 0b 09>,
  generatorPublicKey: <Buffer ac fd fd 62 b2 7e 4f f7 0f 1c 45 0d 8c c8 88 97 f9 d4 e7 1c b7 d8 dc 64 a9 df 7d c4 06 3e 1e 6d>,
  reward: 0n,
  asset: {
    maxHeightPreviouslyForged: 0,
    maxHeightPrevoted: 0,
    seedReveal: <Buffer 4e 60 60 fb 9b 8e e9 b8 13 ef ab ee a0 3f f3 ef>
  },
  signature: <Buffer 1e bd 4a 3a 49 18 db 21 e5 ae 29 46 6c fd b9 b8 85 91 6e 37 65 c6 de 97 c8 43 1b 08 fb a5 97 be 00 14 41 04 03 c1 b7 c4 62 ce ed 50 33 30 61 2b 07 2f ... 14 more bytes>,
  id: <Buffer 5e f3 b5 22 b8 ee 0c f8 c7 c6 23 4d 6f 53 93 f5 16 1c df f1 a1 5f 22 99 af fe 93 8e 5f 6f e7 6b>
}

createAfterGenesisBlockApplyContext

Parameters

{
	modules?: ModuleClass[];
	genesisBlock?: GenesisBlock<T>;
	reducerHandler?: ReducerHandler;
	stateStore?: StateStore;
}

Usage

const sdk = require('klayr-sdk');

let gb = sdk.testing.createGenesisBlock({modules: [sdk.TokenModule,sdk.DPoSModule]});
sdk.testing.createAfterGenesisBlockApplyContext({modules: [sdk.TokenModule],genesisBlock: gb.genesisBlock});
Returns
{
  genesisBlock: {
    header: {
      generatorPublicKey: <Buffer >,
      height: 0,
      previousBlockID: <Buffer >,
      reward: 0n,
      signature: <Buffer >,
      timestamp: 1623154492,
      transactionRoot: <Buffer e3 b0 c4 42 98 fc 1c 14 9a fb f4 c8 99 6f b9 24 27 ae 41 e4 64 9b 93 4c a4 95 99 1b 78 52 b8 55>,
      version: 0,
      asset: [Object],
      id: <Buffer 61 fc 85 5e b6 9d a8 e5 93 90 37 8c 17 14 36 0e 18 a5 57 f8 15 b1 5e 6a 58 54 9d 7a 61 e5 dc e1>
    },
    payload: []
  },
  stateStore: StateStoreMock {
    accountData: [],
    chainData: {},
    consensusData: {},
    _defaultAccount: {},
    account: {
      get: [AsyncFunction: get],
      getOrDefault: [AsyncFunction: getOrDefault],
      getUpdated: [Function: getUpdated],
      set: [AsyncFunction: set],
      del: [AsyncFunction: del]
    },
    chain: {
      networkIdentifier: <Buffer >,
      lastBlockHeaders: [],
      lastBlockReward: 0n,
      get: [AsyncFunction: get],
      set: [AsyncFunction: set]
    },
    consensus: { get: [AsyncFunction: get], set: [AsyncFunction: set] }
  },
  reducerHandler: { invoke: [AsyncFunction: invoke] }
}

createBeforeBlockApplyContext

Parameters

{
	modules?: ModuleClass[];
	genesisBlock?: GenesisBlock<T>;
	reducerHandler?: ReducerHandler;
	stateStore?: StateStore;
}

Usage

const sdk = require('klayr-sdk');

sdk.testing.createBeforeBlockApplyContext({})
Returns
{
  block: undefined,
  stateStore: StateStoreMock {
    accountData: [],
    chainData: {},
    consensusData: {},
    _defaultAccount: {},
    account: {
      get: [AsyncFunction: get],
      getOrDefault: [AsyncFunction: getOrDefault],
      getUpdated: [Function: getUpdated],
      set: [AsyncFunction: set],
      del: [AsyncFunction: del]
    },
    chain: {
      networkIdentifier: <Buffer >,
      lastBlockHeaders: [],
      lastBlockReward: 0n,
      get: [AsyncFunction: get],
      set: [AsyncFunction: set]
    },
    consensus: { get: [AsyncFunction: get], set: [AsyncFunction: set] }
  },
  reducerHandler: { invoke: [AsyncFunction: invoke] }
}

createAfterBlockApplyContext

Parameters

{
	block: Block;
	reducerHandler?: ReducerHandler;
	stateStore?: StateStore;
	consensus?: Consensus;
}

Usage

const sdk = require('klayr-sdk');

sdk.testing.createAfterBlockApplyContext({});
Returns
{
  block: undefined,
  stateStore: StateStoreMock {
    accountData: [],
    chainData: {},
    consensusData: {},
    _defaultAccount: {},
    account: {
      get: [AsyncFunction: get],
      getOrDefault: [AsyncFunction: getOrDefault],
      getUpdated: [Function: getUpdated],
      set: [AsyncFunction: set],
      del: [AsyncFunction: del]
    },
    chain: {
      networkIdentifier: <Buffer >,
      lastBlockHeaders: [],
      lastBlockReward: 0n,
      get: [AsyncFunction: get],
      set: [AsyncFunction: set]
    },
    consensus: { get: [AsyncFunction: get], set: [AsyncFunction: set] }
  },
  reducerHandler: { invoke: [AsyncFunction: invoke] },
  consensus: {
    getDelegates: [AsyncFunction: getDelegates],
    updateDelegates: [AsyncFunction: updateDelegates],
    getFinalizedHeight: [Function: getFinalizedHeight]
  }
}

createTransactionApplyContext

Parameters

{
	transaction: Transaction;
	reducerHandler?: ReducerHandler;
	stateStore?: StateStore;
}

Usage

const sdk = require('klayr-sdk');

sdk.testing.createTransactionApplyContext({});
Returns
{
  transaction: undefined,
  stateStore: StateStoreMock {
    accountData: [],
    chainData: {},
    consensusData: {},
    _defaultAccount: {},
    account: {
      get: [AsyncFunction: get],
      getOrDefault: [AsyncFunction: getOrDefault],
      getUpdated: [Function: getUpdated],
      set: [AsyncFunction: set],
      del: [AsyncFunction: del]
    },
    chain: {
      networkIdentifier: <Buffer >,
      lastBlockHeaders: [],
      lastBlockReward: 0n,
      get: [AsyncFunction: get],
      set: [AsyncFunction: set]
    },
    consensus: { get: [AsyncFunction: get], set: [AsyncFunction: set] }
  },
  reducerHandler: { invoke: [AsyncFunction: invoke] }
}

createApplyAssetContext

Parameters

{
	transaction: Transaction;
	asset: T;
	reducerHandler?: ReducerHandler;
	stateStore?: StateStore;
}

Usage

const sdk = require('klayr-sdk');

sdk.testing.createApplyAssetContext({});
Returns
{
  transaction: undefined,
  stateStore: StateStoreMock {
    accountData: [],
    chainData: {},
    consensusData: {},
    _defaultAccount: {},
    account: {
      get: [AsyncFunction: get],
      getOrDefault: [AsyncFunction: getOrDefault],
      getUpdated: [Function: getUpdated],
      set: [AsyncFunction: set],
      del: [AsyncFunction: del]
    },
    chain: {
      networkIdentifier: <Buffer >,
      lastBlockHeaders: [],
      lastBlockReward: 0n,
      get: [AsyncFunction: get],
      set: [AsyncFunction: set]
    },
    consensus: { get: [AsyncFunction: get], set: [AsyncFunction: set] }
  },
  reducerHandler: { invoke: [AsyncFunction: invoke] },
  asset: undefined
}

createValidateAssetContext

Parameters

{
	transaction: Transaction;
	asset: T;
}

Usage

const sdk = require('klayr-sdk');

sdk.testing.createValidateAssetContext({});
Returns
{ transaction: undefined, asset: undefined }