From 405745b74a8a49f14489e78681773c3d2194d75d Mon Sep 17 00:00:00 2001 From: Benedek Robert George Date: Fri, 8 Mar 2024 13:25:41 +0200 Subject: [PATCH] test: view features tests for bond contract functions Refs : #99 --- src/bond.ts | 2 +- tests/bond.test.ts | 68 +++++++++++++++++++++++++++------------------- 2 files changed, 41 insertions(+), 29 deletions(-) diff --git a/src/bond.ts b/src/bond.ts index d35934b..81cccde 100644 --- a/src/bond.ts +++ b/src/bond.ts @@ -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) ]); diff --git a/tests/bond.test.ts b/tests/bond.test.ts index 8e8dd99..90f9d76 100644 --- a/tests/bond.test.ts +++ b/tests/bond.test.ts @@ -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'); @@ -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; - - // const sameBond: Bond[] = await bondContract.viewBonds( - // ['NEWDNFT-3a8caa'], - // [8] - // ); - - // expect(sameBond).toMatchObject; - - // const sameBond2: Bond[] = await bondContract.viewBonds([ - // 'NEWDNFT-3a8caa-08' - // ]); - // expect(sameBond2).toMatchObject; - - // const compensation: Compensation = await bondContract.viewCompensation( - // 'NEWDNFT-3a8caa', - // 8 - // ); - - // expect(compensation).toMatchObject; + const bond: Bond[] = await bondContract.viewBonds([1]); + expect(bond).toMatchObject; + console.log('bond', bond); + const sameBond: Bond[] = await bondContract.viewBonds( + [tokenIdentifier], + [76] + ); + expect(sameBond).toMatchObject; + const sameBond2: Bond[] = await bondContract.viewBonds([ + createTokenIdentifier(tokenIdentifier, 76) + ]); + expect(sameBond2).toMatchObject; + expect(sameBond).toStrictEqual(sameBond2); + + const singleBond: Bond = await bondContract.viewBond(1); + expect(singleBond).toMatchObject; + expect(singleBond).toStrictEqual(sameBond2[0]); + + const compensation: Compensation = await bondContract.viewCompensation(1); + expect(compensation).toMatchObject; + + const compensations: Compensation[] = await bondContract.viewCompensations([ + { tokenIdentifier: tokenIdentifier, nonce: 76 } + ]); + expect(compensations).toMatchObject; + expect(compensations[0]).toStrictEqual(compensation); + + const pagedCompensations: Compensation[] = + await bondContract.viewPagedCompensations(0, 2); + expect(pagedCompensations).toMatchObject; + expect(pagedCompensations.length).toBe(3); + expect(pagedCompensations[0]).toStrictEqual(compensation); }); });