Skip to content

Commit

Permalink
add tests for expiryInfo
Browse files Browse the repository at this point in the history
Signed-off-by: georgi-l95 <glazarov95@gmail.com>

update flow

Signed-off-by: georgi-l95 <glazarov95@gmail.com>

Enable tests

Signed-off-by: Nana Essilfie-Conduah <nana@swirldslabs.com>

test refactor

Signed-off-by: georgi-l95 <glazarov95@gmail.com>

test

Signed-off-by: georgi-l95 <glazarov95@gmail.com>

revert some changes

Signed-off-by: georgi-l95 <glazarov95@gmail.com>

revert some changes

Signed-off-by: georgi-l95 <glazarov95@gmail.com>

Acceptance test index rework

Signed-off-by: georgi-l95 <glazarov95@gmail.com>

remove typo

Signed-off-by: georgi-l95 <glazarov95@gmail.com>

test

Signed-off-by: georgi-l95 <glazarov95@gmail.com>

test

Signed-off-by: georgi-l95 <glazarov95@gmail.com>

x

Signed-off-by: georgi-l95 <glazarov95@gmail.com>

x

Signed-off-by: georgi-l95 <glazarov95@gmail.com>

x

Signed-off-by: georgi-l95 <glazarov95@gmail.com>
  • Loading branch information
georgi-l95 committed Sep 9, 2022
1 parent 26d110c commit bbd6115
Show file tree
Hide file tree
Showing 11 changed files with 534 additions and 16 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"integration:prerequisite": "ts-node packages/server/tests/helpers/prerequisite.ts"
},
"dependencies": {
"@hashgraph/hedera-local": "^1.2.0",
"@open-rpc/schema-utils-js": "^1.16.1",
"@types/find-config": "^1.0.1",
"keyv-file": "^0.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"pino-pretty": "^7.6.1"
},
"devDependencies": {
"@hashgraph/hedera-local": "^1.2.0",
"@hashgraph/hedera-local": "^1.1.0",
"@hashgraph/sdk": "^2.18.0",
"@koa/cors": "^3.1.0",
"@types/chai": "^4.3.0",
Expand Down
108 changes: 102 additions & 6 deletions packages/server/tests/acceptance/htsPrecompile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import BaseHTSJson from '../contracts/BaseHTS.json';

describe('HTS Precompile Acceptance Tests', async function () {
this.timeout(240 * 1000); // 240 seconds
const { servicesNode, relay } = global;
const { servicesNode, mirrorNode, relay } = global;

const TX_SUCCESS_CODE = 22;
const TOKEN_NAME = 'tokenName';
Expand Down Expand Up @@ -216,7 +216,7 @@ describe('HTS Precompile Acceptance Tests', async function () {
});
});

describe('HTS Precompile Get Token Info Tests', async function() {
xdescribe('HTS Precompile Get Token Info Tests', async function() {
it('should be able to get fungible token info', async () => {
const tx = await baseHTSContract.getFungibleTokenInfoPublic(HTSTokenContractAddress);

Expand Down Expand Up @@ -252,7 +252,7 @@ describe('HTS Precompile Acceptance Tests', async function () {
});
});

describe('HTS Precompile Freeze/Unfreeze Tests', async function() {
xdescribe('HTS Precompile Freeze/Unfreeze Tests', async function() {
async function checkTokenFrozen(contractOwner, tokenAddress, expectedValue: boolean) {
const txBefore = await contractOwner.isFrozenPublic(tokenAddress, accounts[0].wallet.address, { gasLimit: 1_000_000 });
const txBeforeReceipt = await txBefore.wait();
Expand Down Expand Up @@ -357,7 +357,7 @@ describe('HTS Precompile Acceptance Tests', async function () {
});
});

describe('HTS Precompile Pause/Unpause Tests', async function() {
xdescribe('HTS Precompile Pause/Unpause Tests', async function() {

it('should be able to pause fungible token', async () => {
const txTokenInfoBefore = await baseHTSContract.getTokenInfoPublic(HTSTokenContractAddress);
Expand Down Expand Up @@ -510,7 +510,7 @@ describe('HTS Precompile Acceptance Tests', async function () {
});
});

describe('HTS Precompile KYC Tests', async function() {
xdescribe('HTS Precompile KYC Tests', async function() {
async function checkKyc(contractOwner, tokenAddress, accountAddress, expectedValue: boolean) {
const tx = await contractOwner.isKycPublic(tokenAddress, accountAddress, { gasLimit: 1_000_000 });
const responseCodeIsKyc = (await tx.wait()).events.filter(e => e.event === 'ResponseCode')[0].args.responseCode;
Expand Down Expand Up @@ -566,7 +566,7 @@ describe('HTS Precompile Acceptance Tests', async function () {
});
});

describe('HTS Precompile Custom Fees Tests', async function() {
xdescribe('HTS Precompile Custom Fees Tests', async function() {
it('should be able to get a custom token fees', async function() {
const baseHTSContract = new ethers.Contract(BaseHTSContractAddress, BaseHTSJson.abi, accounts[0].wallet);

Expand All @@ -586,6 +586,102 @@ describe('HTS Precompile Acceptance Tests', async function () {
});
});

describe('HTS Precompile Token Expiry Info Tests', async function() {
const AUTO_RENEW_PERIOD = 8000000;
const NEW_AUTO_RENEW_PERIOD = 7999900;
const AUTO_RENEW_SECOND = 0;

//Expiry Info auto renew account returns account id from type - 0x000000000000000000000000000000000000048C
//We expect account to be evm address, but because we can't compute one address for the other, we have to make a mirror node query to get expiry info auto renew evm address
async function mirrorNodeAddressReq(address){
const accountEvmAddress = await mirrorNode.get(`/accounts/${address}?transactiontype=cryptotransfer`);
return accountEvmAddress.evm_address;
}

it('should be able to get and update fungible token expiry info', async function() {
//get current epoch + auto renew period , which result to expiry info second
const epoch = parseInt((Date.now()/1000 + NEW_AUTO_RENEW_PERIOD).toFixed(0));

// get current expiry info
const getTokenExpiryInfoTxBefore = await baseHTSContract.getTokenExpiryInfoPublic(HTSTokenContractAddress);
const responseCode = (await getTokenExpiryInfoTxBefore.wait()).events.filter(e => e.event === 'ResponseCode')[0].args.responseCode;
const tokenExpiryInfoBefore = (await getTokenExpiryInfoTxBefore.wait()).events.filter(e => e.event === 'TokenExpiryInfo')[0].args.expiryInfo;

const renewAccountEvmAddress = await mirrorNodeAddressReq(tokenExpiryInfoBefore.autoRenewAccount);

expect(responseCode).to.equal(TX_SUCCESS_CODE);
expect(tokenExpiryInfoBefore.autoRenewPeriod).to.equal(AUTO_RENEW_PERIOD);
expect(renewAccountEvmAddress).to.equal(`0x${accounts[0].address}`);

const expiryInfo = {
second: AUTO_RENEW_SECOND,
autoRenewAccount: `${BaseHTSContractAddress}`,
autoRenewPeriod: NEW_AUTO_RENEW_PERIOD
};
// update expiry info
const updateTokenExpiryInfoTx = (await baseHTSContract.updateTokenExpiryInfoPublic(HTSTokenContractAddress, expiryInfo, { gasLimit: 1_000_000 }));
const updateExpiryInfoResponseCode = (await updateTokenExpiryInfoTx.wait()).events.filter(e => e.event === 'ResponseCode')[0].args.responseCode;

// get updated expiryInfo
const getTokenExpiryInfoTxAfter = (await baseHTSContract.getTokenExpiryInfoPublic(HTSTokenContractAddress));
const getExpiryInfoResponseCode = (await getTokenExpiryInfoTxAfter.wait()).events.filter(e => e.event === 'ResponseCode')[0].args.responseCode;
const tokenExpiryInfoAfter = (await getTokenExpiryInfoTxAfter.wait()).events.filter(e => e.event === 'TokenExpiryInfo')[0].args.expiryInfo;

const newRenewAccountEvmAddress = await mirrorNodeAddressReq(tokenExpiryInfoAfter.autoRenewAccount);
const expectedRenewAddress = `0x${BaseHTSContractAddress.substring(2).toUpperCase()}`;

expect(updateExpiryInfoResponseCode).to.equal(TX_SUCCESS_CODE);
expect(getExpiryInfoResponseCode).to.equal(TX_SUCCESS_CODE);
expect(tokenExpiryInfoAfter.autoRenewPeriod).to.equal(expiryInfo.autoRenewPeriod);
expect(newRenewAccountEvmAddress).to.equal(expectedRenewAddress);

//use close to with delta 200 seconds, because we don't know the exact second it was set to expiry
expect(tokenExpiryInfoAfter.second).to.be.closeTo(epoch, 200);
});

it('should be able to get and update non fungible token expiry info', async function() {
//get current epoch + auto renew period , which result to expiry info second
const epoch = parseInt((Date.now()/1000 + NEW_AUTO_RENEW_PERIOD).toFixed(0));
// get current expiry info
const getTokenExpiryInfoTxBefore = (await baseHTSContract.getTokenExpiryInfoPublic(NftHTSTokenContractAddress));
const responseCode = (await getTokenExpiryInfoTxBefore.wait()).events.filter(e => e.event === 'ResponseCode')[0].args.responseCode;
const tokenExpiryInfoBefore = (await getTokenExpiryInfoTxBefore.wait()).events.filter(e => e.event === 'TokenExpiryInfo')[0].args.expiryInfo;

//Expiry Info auto renew account returns account id from type - 0x000000000000000000000000000000000000048C
//We expect account to be evm address, but because we can't compute one address for the other, we have to make a mirror node query to get expiry info auto renew evm address
const renewAccountEvmAddress = await mirrorNodeAddressReq(tokenExpiryInfoBefore.autoRenewAccount);

expect(responseCode).to.equal(TX_SUCCESS_CODE);
expect(tokenExpiryInfoBefore.autoRenewPeriod).to.equal(8000000);
expect(renewAccountEvmAddress).to.equal(`0x${accounts[0].address}`);

// update expiry info
const expiryInfo = {
second: AUTO_RENEW_SECOND,
autoRenewAccount: BaseHTSContractAddress,
autoRenewPeriod: NEW_AUTO_RENEW_PERIOD
}
const updateTokenExpiryInfoTx = (await baseHTSContract.updateTokenExpiryInfoPublic(NftHTSTokenContractAddress, expiryInfo, { gasLimit: 1_000_000 }));
const updateExpiryInfoResponseCode = (await updateTokenExpiryInfoTx.wait()).events.filter(e => e.event === 'ResponseCode')[0].args.responseCode;

// get updated expiryInfo
const getTokenExpiryInfoTxAfter = (await baseHTSContract.getTokenExpiryInfoPublic(NftHTSTokenContractAddress));
const getExpiryInfoResponseCode = (await getTokenExpiryInfoTxAfter.wait()).events.filter(e => e.event === 'ResponseCode')[0].args.responseCode;
const tokenExpiryInfoAfter = (await getTokenExpiryInfoTxAfter.wait()).events.filter(e => e.event === 'TokenExpiryInfo')[0].args.expiryInfo;

const newRenewAccountEvmAddress = await mirrorNodeAddressReq(tokenExpiryInfoAfter.autoRenewAccount);
const expectedRenewAddress = `0x${BaseHTSContractAddress.substring(2).toUpperCase()}`;

expect(updateExpiryInfoResponseCode).to.equal(TX_SUCCESS_CODE);
expect(getExpiryInfoResponseCode).to.equal(TX_SUCCESS_CODE);
expect(tokenExpiryInfoAfter.autoRenewPeriod).to.equal(expiryInfo.autoRenewPeriod);
expect(newRenewAccountEvmAddress).to.equal(expectedRenewAddress);

//use close to with delta 200 seconds, because we don't know the exact second it was set to expiry
expect(tokenExpiryInfoAfter.second).to.be.closeTo(epoch, 200);
});
});

describe('HTS Precompile Delete Token Tests', async function() {
it('should be able to delete a token', async function() {
const createdTokenAddress = await createHTSToken();
Expand Down
22 changes: 15 additions & 7 deletions packages/server/tests/acceptance/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ describe('RPC Server Acceptance Tests', function () {
logger.info(`OPERATOR_ID_MAIN: ${process.env.OPERATOR_ID_MAIN}`);
logger.info(`MIRROR_NODE_URL: ${process.env.MIRROR_NODE_URL}`);
logger.info(`E2E_RELAY_HOST: ${process.env.E2E_RELAY_HOST}`);



if (USE_LOCAL_NODE === 'true') {
runLocalHederaNetwork();
}
Expand All @@ -95,7 +94,7 @@ describe('RPC Server Acceptance Tests', function () {
if (USE_LOCAL_NODE === 'true') {
// stop local-node
logger.info('Shutdown local node');
shell.exec('npx hedera stop');
shell.exec('hedera stop');
}

// stop relay
Expand All @@ -116,14 +115,23 @@ describe('RPC Server Acceptance Tests', function () {

function runLocalHederaNetwork() {
// set env variables for docker images until local-node is updated
process.env['NETWORK_NODE_IMAGE_TAG'] = '0.30.0-alpha.0';
process.env['HAVEGED_IMAGE_TAG'] = '0.30.0-alpha.0';
process.env['MIRROR_IMAGE_TAG'] = '0.64.0';
process.env['NETWORK_NODE_IMAGE_TAG'] = '0.30.0-alpha.1';
process.env['HAVEGED_IMAGE_TAG'] = '0.30.0-alpha.1';
process.env['MIRROR_IMAGE_TAG'] = '0.64.0-beta2';

logger.trace(`Docker container versions, services: ${process.env['NETWORK_NODE_IMAGE_TAG']}, mirror: ${process.env['MIRROR_IMAGE_TAG']}`);

// start local-node

logger.debug('Installing local node...');
shell.exec(`npm install @hashgraph/hedera-local && hedera stop`);

logger.debug('Turning on compression...');
shell.exec(`echo 'hedera.recordStream.compressFilesOnCreation=true' >> node_modules/@hashgraph/hedera-local/compose-network/network-node/data/config/bootstrap.properties`);
shell.exec(`sed -i 's/ STREAM_EXTENSION: "rcd"/ STREAM_EXTENSION: "rcd.gz"/' node_modules/@hashgraph/hedera-local/docker-compose.yml`);

logger.debug('Start local node');
shell.exec('npx hedera restart');
shell.exec(`hedera start -d`);
logger.trace('Hedera Hashgraph local node env started');
}

Expand Down
Loading

0 comments on commit bbd6115

Please sign in to comment.