Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Update test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Phanco committed Nov 24, 2023
1 parent 2d5e8d2 commit 8de3702
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ export class ChainConnectorPlugin extends BasePlugin<ChainConnectorPluginConfig>
this._chainConnectorStore.close();
}

public _getCcuFee(tx: Record<string, unknown>): bigint {
if (this.config.ccuFee && this.config.ccuFee !== '0') {
return BigInt(this.config.ccuFee);
}
return transactions.computeMinFee(tx);
}

private async _newBlockReceivingChainHandler(_?: Record<string, unknown>) {
try {
const { finalizedHeight } = await this._receivingChainClient.invoke<{
Expand Down Expand Up @@ -842,9 +849,7 @@ export class ChainConnectorPlugin extends BasePlugin<ChainConnectorPluginConfig>

const tx = new Transaction({
...txWithoutFee,
fee: this.config.ccuFee
? BigInt(this.config.ccuFee)
: transactions.computeMinFee(txWithoutFee),
fee: this._getCcuFee(txWithoutFee),
});

tx.sign(chainID, this._chainConnectorStore.privateKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const configSchema = {
default: {
ccuFrequency: CCU_FREQUENCY,
isSaveCCU: false,
ccuFee: '0',
maxCCUSize: CCU_TOTAL_CCM_SIZE,
registrationHeight: DEFAULT_REGISTRATION_HEIGHT,
ccuSaveLimit: DEFAULT_CCU_SAVE_LIMIT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
CrossChainUpdateTransactionParams,
Certificate,
BFTHeights,
transactions,
} from 'lisk-sdk';
import { when } from 'jest-when';
import {
Expand All @@ -42,6 +43,7 @@ import {
CCM_PROCESSED,
CCU_TOTAL_CCM_SIZE,
EMPTY_BYTES,
COMMAND_NAME_SUBMIT_MAINCHAIN_CCU,
} from '../../src/constants';
import { getSampleCCM } from '../utils/sampleCCM';
import * as plugins from '../../src/chain_connector_plugin';
Expand Down Expand Up @@ -150,7 +152,7 @@ describe('ChainConnectorPlugin', () => {
const defaultPrivateKey =
'6c5e2b24ff1cc99da7a49bd28420b93b2a91e2e2a3b0a0ce07676966b707d3c2859bbd02747cf8e26dab592c02155dfddd4a16b0fe83fd7e7ffaec0b5391f3f7';
const defaultPassword = '123';
const defaultCCUFee = '100000000';
const defaultCCUFee = '500000';

const getApiClientMock = () => ({
disconnect: jest.fn(),
Expand Down Expand Up @@ -1031,6 +1033,33 @@ describe('ChainConnectorPlugin', () => {
});
});

describe('_getCcuFee', () => {
const transactionTemplate = {
module: MODULE_NAME_INTEROPERABILITY,
command: COMMAND_NAME_SUBMIT_MAINCHAIN_CCU,
nonce: BigInt(0),
senderPublicKey: cryptography.utils.getRandomBytes(BLS_PUBLIC_KEY_LENGTH),
params: cryptography.utils.getRandomBytes(100),
signatures: [],
};

it('should return config.ccuFee when it exists', async () => {
await initChainConnectorPlugin(chainConnectorPlugin, defaultConfig);
expect(chainConnectorPlugin['_getCcuFee'](transactionTemplate)).toBe(BigInt(defaultCCUFee));
});

it('should calculate by `computeMinFee` when config.ccuFee does not exist', async () => {
const txWithoutFee = {
...defaultConfig,
ccuFee: '0',
};

await initChainConnectorPlugin(chainConnectorPlugin, txWithoutFee);
expect(chainConnectorPlugin['_getCcuFee'](txWithoutFee)).toBe(
transactions.computeMinFee(txWithoutFee),
);
});
});
describe('_computeCCUParams', () => {
let sampleCCMsWithEvents: CCMsFromEvents[];
let sampleBlockHeaders: BlockHeader[];
Expand Down

0 comments on commit 8de3702

Please sign in to comment.