Skip to content

Commit

Permalink
test: view features tests for bond contract functions
Browse files Browse the repository at this point in the history
Refs : #99
  • Loading branch information
911-Benedek-RobertGeorge committed Mar 8, 2024
1 parent 72280c2 commit 405745b
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/bond.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export class BondContract extends Contract {
* @param end_index index to end
*/
async viewPagedCompensations(startIndex: number, endIndex: number) {
const interaction = this.contract.methodsExplicit.viewPagedCompensations([
const interaction = this.contract.methodsExplicit.getPagedCompensations([
new U64Value(startIndex),
new U64Value(endIndex)
]);
Expand Down
68 changes: 40 additions & 28 deletions tests/bond.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { BondContract, Compensation, State } from '../src';
import {
BondContract,
Compensation,
State,
createTokenIdentifier,
dataNftTokenIdentifier
} from '../src';
import { Bond } from '../src';
import { ErrContractAddressNotSet } from '../src/errors';

describe('Bond test', () => {
const tokenIdentifier = dataNftTokenIdentifier.devnet;
test('#test no deploy', () => {
try {
const bondContract = new BondContract('testnet');
Expand All @@ -14,42 +20,48 @@ describe('Bond test', () => {
const bondContract = new BondContract('devnet');

const bondPaymentToken = await bondContract.viewBondPaymentToken();

expect(typeof bondPaymentToken).toBe('string');

const lockPeriodsWithBonds = await bondContract.viewLockPeriodsWithBonds();

expect(typeof lockPeriodsWithBonds).toBe('object');

const contractState = await bondContract.viewContractState();

expect(Object.values(State).includes(contractState)).toBe(true);

const acceptedCallers = await bondContract.viewAcceptedCallers();

expect(typeof acceptedCallers).toBe('object');

// const bond: Bond[] = await bondContract.viewBonds([1]);

// expect(bond).toMatchObject<Bond>;

// const sameBond: Bond[] = await bondContract.viewBonds(
// ['NEWDNFT-3a8caa'],
// [8]
// );

// expect(sameBond).toMatchObject<Bond[]>;

// const sameBond2: Bond[] = await bondContract.viewBonds([
// 'NEWDNFT-3a8caa-08'
// ]);
// expect(sameBond2).toMatchObject<Bond[]>;

// const compensation: Compensation = await bondContract.viewCompensation(
// 'NEWDNFT-3a8caa',
// 8
// );

// expect(compensation).toMatchObject<Compensation>;
const bond: Bond[] = await bondContract.viewBonds([1]);
expect(bond).toMatchObject<Bond>;
console.log('bond', bond);
const sameBond: Bond[] = await bondContract.viewBonds(
[tokenIdentifier],
[76]
);
expect(sameBond).toMatchObject<Bond[]>;
const sameBond2: Bond[] = await bondContract.viewBonds([
createTokenIdentifier(tokenIdentifier, 76)
]);
expect(sameBond2).toMatchObject<Bond[]>;
expect(sameBond).toStrictEqual(sameBond2);

const singleBond: Bond = await bondContract.viewBond(1);
expect(singleBond).toMatchObject<Bond>;
expect(singleBond).toStrictEqual(sameBond2[0]);

const compensation: Compensation = await bondContract.viewCompensation(1);
expect(compensation).toMatchObject<Compensation>;

const compensations: Compensation[] = await bondContract.viewCompensations([
{ tokenIdentifier: tokenIdentifier, nonce: 76 }
]);
expect(compensations).toMatchObject<Compensation[]>;
expect(compensations[0]).toStrictEqual(compensation);

const pagedCompensations: Compensation[] =
await bondContract.viewPagedCompensations(0, 2);
expect(pagedCompensations).toMatchObject<Compensation[]>;
expect(pagedCompensations.length).toBe(3);
expect(pagedCompensations[0]).toStrictEqual(compensation);
});
});

0 comments on commit 405745b

Please sign in to comment.