Skip to content

Commit

Permalink
feat(test): add new test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
RutvikGhaskataEalf committed Aug 14, 2024
1 parent e785773 commit 7fdc987
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<!-- | Statements | Branches | Functions | Lines |
| --------------------------- | ----------------------- | ------------------------- | ----------------- |
| ![Statements](https://img.shields.io/badge/statements-96.16%25-brightgreen.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-92.62%25-brightgreen.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-98.61%25-brightgreen.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-96.1%25-brightgreen.svg?style=flat) | -->
| ![Statements](https://img.shields.io/badge/statements-97.98%25-brightgreen.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-95.49%25-brightgreen.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-98.61%25-brightgreen.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-98%25-brightgreen.svg?style=flat) | -->


## 1. Introduction
Expand Down
10 changes: 10 additions & 0 deletions test/unit/chain/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ describe('chain should work', () => {
const result = chain.extractArgumentsIntoObject(args);
expect(result.isSync).toBeTruthy();
});
test('test refBlockNumberStrategy argument into object', () => {
// Arrange
const args = [{ refBlockNumberStrategy: 10 }];

// Act
const result = chain.extractArgumentsIntoObject(args);

// Assert
expect(result.refBlockNumberStrategy).toBe(10);
});
test('test is concrete contract when sync', async () => {
const aelf = new AElf(new AElf.providers.HttpProvider(stageEndpoint));
const { GenesisContractAddress } = await aelf.chain.getChainStatus();
Expand Down
92 changes: 91 additions & 1 deletion test/unit/contract/contractMethod.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ContractMethod from '../../../src/contract/contractMethod';
import ContractFactory from '../../../src/contract/index';
import AElf from '../../../src/index';
import { noop } from '../../../src/util/utils';
import { noop, uint8ArrayToHex } from '../../../src/util/utils';
const stageEndpoint = 'https://tdvw-test-node.aelf.io/';
describe('token contract with transfer method', () => {
const aelf = new AElf(new AElf.providers.HttpProvider(stageEndpoint));
Expand Down Expand Up @@ -322,4 +322,94 @@ describe('token contract with GetBalance method', () => {
);
expect(factory.GetBalance.outputType).toEqual(contractMethod._outputType);
});

test('test prepareParametersAsync with valid refBlockNumberStrategy', async () => {
const result = await contractMethod.prepareParametersAsync([
{
symbol: 'ELF',
owner: 'soAcchsFZGEsFeaEsk9tyMnFauPgJfMyZMRrfcntGjrtC7YvE',
refBlockNumberStrategy: -1,
},
]);
expect(typeof result).toBe('string');
}, 10000);

test('test prepareParametersAsync with invalid refBlockNumberStrategy type', async () => {
await expect(
contractMethod.prepareParametersAsync([
{
symbol: 'ELF',
owner: 'soAcchsFZGEsFeaEsk9tyMnFauPgJfMyZMRrfcntGjrtC7YvE',
refBlockNumberStrategy: 'invalid type',
},
])
).rejects.toThrow('Invalid type, refBlockNumberStrategy must be number');
}, 10000);

test('test prepareParametersAsync with positive refBlockNumberStrategy', async () => {
await expect(
contractMethod.prepareParametersAsync([
{
symbol: 'ELF',
owner: 'soAcchsFZGEsFeaEsk9tyMnFauPgJfMyZMRrfcntGjrtC7YvE',
refBlockNumberStrategy: 1,
},
])
).rejects.toThrow('refBlockNumberStrategy must be less than 0');
}, 10000);

test('test prepareParametersAsync without refBlockNumberStrategy', async () => {
const result = await contractMethod.prepareParametersAsync([
{
symbol: 'ELF',
owner: 'soAcchsFZGEsFeaEsk9tyMnFauPgJfMyZMRrfcntGjrtC7YvE',
},
]);
expect(typeof result).toBe('string');
}, 10000);

test('test prepareParameters with valid refBlockNumberStrategy', () => {
const result = contractMethod.prepareParameters([
{
symbol: 'ELF',
owner: 'soAcchsFZGEsFeaEsk9tyMnFauPgJfMyZMRrfcntGjrtC7YvE',
refBlockNumberStrategy: -1,
},
]);
expect(typeof result).toBe('string');
}, 10000);

test('test prepareParameters with invalid refBlockNumberStrategy type', () => {
expect(() => {
contractMethod.prepareParameters([
{
symbol: 'ELF',
owner: 'soAcchsFZGEsFeaEsk9tyMnFauPgJfMyZMRrfcntGjrtC7YvE',
refBlockNumberStrategy: 'invalid-type', // invalid type
},
]);
}).toThrow('Invalid type, refBlockNumberStrategy must be number');
}, 10000);

test('test prepareParameters with refBlockNumberStrategy greater than 0', () => {
expect(() => {
contractMethod.prepareParameters([
{
symbol: 'ELF',
owner: 'soAcchsFZGEsFeaEsk9tyMnFauPgJfMyZMRrfcntGjrtC7YvE',
refBlockNumberStrategy: 1, // invalid value
},
]);
}).toThrow('refBlockNumberStrategy must be less than 0');
}, 10000);

test('test prepareParameters without refBlockNumberStrategy', () => {
const result = contractMethod.prepareParameters([
{
symbol: 'ELF',
owner: 'soAcchsFZGEsFeaEsk9tyMnFauPgJfMyZMRrfcntGjrtC7YvE',
},
]);
expect(typeof result).toBe('string');
}, 10000);
});
2 changes: 2 additions & 0 deletions test/unit/util/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ describe('test utils', () => {
expect(() => base58.encode(null, 'hex')).toThrow('"data" argument must be an Array of Buffers');
expect(base58.encode('qwe123', 'utf8')).toBe('7NjemqtmHiYjxe');
expect(base58.decode('7NjemqtmHiYjxe', 'utf8')).toBe('qwe123');
expect(() => base58.decode('2MTJUAViVu6ctF')).not.toThrow();
expect(() => base58.decode('2MTJUAViVu6ctG')).toThrow('Invalid checksum');
});

test('test chainId convertor chainIdToBase58 and base58ToChainId', () => {
Expand Down

0 comments on commit 7fdc987

Please sign in to comment.