Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dapp-feat: finished integrating API methods for TokenQueryContract #370

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,264 @@
/*-
*
* Hedera Smart Contracts
*
* Copyright (C) 2023 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

import {
queryTokenGeneralInfomation,
queryTokenPermissionInformation,
queryTokenRelationInformation,
queryTokenSpecificInfomation,
queryTokenValidity,
} from '@/api/hedera/tokenQuery-interactions';
import { Contract } from 'ethers';

describe('TokenQueryContract Test Suite', () => {
// mock states
const keyType = 1;
const serialNumber = 36;
const mockedEventReturnedValue = 'mockedEventReturnedValue';
const ownerAddress = '0xCC07a8243578590d55c5708D7fB453245350Cc2A';
const spenderAddress = '0x34810E139b451e0a4c67d5743E956Ac8990842A8';
const hederaTokenAddress = '0x00000000000000000000000000000000000084b7';
const txHash = '0x63424020a69bf46a0669f46dd66addba741b9c02d37fab1686428f5209bc759d';

// prepare contract mocked value
const contractMockedResolvedValue = (eventName: string) => {
return jest.fn().mockResolvedValue({
wait: jest.fn().mockResolvedValue({
logs: [
{
fragment: {
name: eventName,
},
data: mockedEventReturnedValue,
},
],
hash: txHash,
}),
});
};

// mock baseContract object
const baseContract = {
isTokenPublic: contractMockedResolvedValue('IsToken'),
isFrozenPublic: contractMockedResolvedValue('Frozen'),
isKycPublic: contractMockedResolvedValue('KycGranted'),
getTokenKeyPublic: contractMockedResolvedValue('TokenKey'),
getTokenInfoPublic: contractMockedResolvedValue('TokenInfo'),
getTokenTypePublic: contractMockedResolvedValue('TokenType'),
allowancePublic: contractMockedResolvedValue('AllowanceValue'),
isApprovedForAllPublic: contractMockedResolvedValue('Approved'),
getApprovedPublic: contractMockedResolvedValue('ApprovedAddress'),
getTokenCustomFeesPublic: contractMockedResolvedValue('TokenCustomFees'),
getTokenExpiryInfoPublic: contractMockedResolvedValue('TokenExpiryInfo'),
getFungibleTokenInfoPublic: contractMockedResolvedValue('FungibleTokenInfo'),
getNonFungibleTokenInfoPublic: contractMockedResolvedValue('NonFungibleTokenInfo'),
getTokenDefaultKycStatusPublic: contractMockedResolvedValue('TokenDefaultKycStatus'),
getTokenDefaultFreezeStatusPublic: contractMockedResolvedValue('TokenDefaultFreezeStatus'),
};

describe('queryTokenValidity test suite', () => {
it('should execute queryTokenValidity then return info value from event', async () => {
const txRes = await queryTokenValidity(
baseContract as unknown as Contract,
hederaTokenAddress
);

expect(txRes.err).toBeNull;
expect(txRes.transactionHash).toBe(txHash);
expect(txRes.IsToken).toBe(mockedEventReturnedValue);
});
});

describe('queryTokenGeneralInfomation test suite', () => {
it('should execute queryTokenGeneralInfomation wit API === "TOKEN_INFO" then return info value from event', async () => {
const txRes = await queryTokenGeneralInfomation(
baseContract as unknown as Contract,
'TOKEN_INFO',
hederaTokenAddress
);

expect(txRes.err).toBeNull;
expect(txRes.transactionHash).toBe(txHash);
expect(txRes.TokenInfo).toBe(mockedEventReturnedValue);
});

it('should execute queryTokenGeneralInfomation wit API === "FUNGIBLE_INFO" then return info value from event', async () => {
const txRes = await queryTokenGeneralInfomation(
baseContract as unknown as Contract,
'FUNGIBLE_INFO',
hederaTokenAddress
);

expect(txRes.err).toBeNull;
expect(txRes.transactionHash).toBe(txHash);
expect(txRes.FungibleTokenInfo).toBe(mockedEventReturnedValue);
});

it('should execute queryTokenGeneralInfomation wit API === "NON_FUNFIBLE_INFO" then return info value from event', async () => {
const txRes = await queryTokenGeneralInfomation(
baseContract as unknown as Contract,
'NON_FUNFIBLE_INFO',
hederaTokenAddress,
serialNumber
);

expect(txRes.err).toBeNull;
expect(txRes.transactionHash).toBe(txHash);
expect(txRes.NonFungibleTokenInfo).toBe(mockedEventReturnedValue);
});
});

describe('queryTokenSpecificInfomation test suite', () => {
it('should execute queryTokenSpecificInfomation wit API === "KYC_STATUS" then return info value from event', async () => {
const txRes = await queryTokenSpecificInfomation(
baseContract as unknown as Contract,
'KYC_STATUS',
hederaTokenAddress
);

expect(txRes.err).toBeNull;
expect(txRes.transactionHash).toBe(txHash);
expect(txRes.TokenDefaultKycStatus).toBe(mockedEventReturnedValue);
});

it('should execute queryTokenSpecificInfomation wit API === "FREEZE_STATUS" then return info value from event', async () => {
const txRes = await queryTokenSpecificInfomation(
baseContract as unknown as Contract,
'FREEZE_STATUS',
hederaTokenAddress
);

expect(txRes.err).toBeNull;
expect(txRes.transactionHash).toBe(txHash);
expect(txRes.TokenDefaultFreezeStatus).toBe(mockedEventReturnedValue);
});

it('should execute queryTokenSpecificInfomation wit API === "CUSTOM_FEES" then return info value from event', async () => {
const txRes = await queryTokenSpecificInfomation(
baseContract as unknown as Contract,
'CUSTOM_FEES',
hederaTokenAddress
);

expect(txRes.err).toBeNull;
expect(txRes.transactionHash).toBe(txHash);
expect(txRes.TokenCustomFees).toBe(mockedEventReturnedValue);
});

it('should execute queryTokenSpecificInfomation wit API === "TOKEN_TYPE" then return info value from event', async () => {
const txRes = await queryTokenSpecificInfomation(
baseContract as unknown as Contract,
'TOKEN_TYPE',
hederaTokenAddress
);

expect(txRes.err).toBeNull;
expect(txRes.transactionHash).toBe(txHash);
expect(txRes.TokenType).toBe(mockedEventReturnedValue);
});

it('should execute queryTokenSpecificInfomation wit API === "TOKEN_KEYS" then return info value from event', async () => {
const txRes = await queryTokenSpecificInfomation(
baseContract as unknown as Contract,
'TOKEN_KEYS',
hederaTokenAddress,
keyType as any
);

expect(txRes.err).toBeNull;
expect(txRes.transactionHash).toBe(txHash);
expect(txRes.TokenKey).toBe(mockedEventReturnedValue);
});
});

describe('queryTokenPermissionInformation test suite', () => {
it('should execute queryTokenPermissionInformation wit API === "ALLOWANCE" then return info value from event', async () => {
const txRes = await queryTokenPermissionInformation(
baseContract as unknown as Contract,
'ALLOWANCE',
hederaTokenAddress,
ownerAddress,
spenderAddress
);

expect(txRes.err).toBeNull;
expect(txRes.transactionHash).toBe(txHash);
expect(txRes.AllowanceValue).toBe(mockedEventReturnedValue);
});

it('should execute queryTokenPermissionInformation wit API === "GET_APPROVED" then return info value from event', async () => {
const txRes = await queryTokenPermissionInformation(
baseContract as unknown as Contract,
'GET_APPROVED',
hederaTokenAddress,
ownerAddress,
spenderAddress,
serialNumber
);

expect(txRes.err).toBeNull;
expect(txRes.transactionHash).toBe(txHash);
expect(txRes.ApprovedAddress).toBe(mockedEventReturnedValue);
});

it('should execute queryTokenPermissionInformation wit API === "IS_APPROVAL" then return info value from event', async () => {
const txRes = await queryTokenPermissionInformation(
baseContract as unknown as Contract,
'IS_APPROVAL',
hederaTokenAddress,
ownerAddress,
spenderAddress,
serialNumber
);

expect(txRes.err).toBeNull;
expect(txRes.transactionHash).toBe(txHash);
expect(txRes.Approved).toBe(mockedEventReturnedValue);
});
});

describe('queryTokenRelationInformation test suite', () => {
it('should execute queryTokenRelationInformation wit API === "IS_KYC" then return info value from event', async () => {
const txRes = await queryTokenRelationInformation(
baseContract as unknown as Contract,
'IS_KYC',
hederaTokenAddress,
ownerAddress
);

expect(txRes.err).toBeNull;
expect(txRes.transactionHash).toBe(txHash);
expect(txRes.KycGranted).toBe(mockedEventReturnedValue);
});

it('should execute queryTokenRelationInformation wit API === "IS_FROZEN" then return info value from event', async () => {
const txRes = await queryTokenRelationInformation(
baseContract as unknown as Contract,
'IS_FROZEN',
hederaTokenAddress,
ownerAddress
);

expect(txRes.err).toBeNull;
expect(txRes.transactionHash).toBe(txHash);
expect(txRes.Frozen).toBe(mockedEventReturnedValue);
});
});
});
Loading