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

Add HTS Precompile Acceptance Tests for Expiry Info methods #467

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
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
98 changes: 97 additions & 1 deletion 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 @@ -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
32 changes: 22 additions & 10 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,15 +115,28 @@ 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['NETWORK_NODE_IMAGE_TAG'] = '0.30.0-alpha.2';
process.env['HAVEGED_IMAGE_TAG'] = '0.30.0-alpha.2';
process.env['MIRROR_IMAGE_TAG'] = '0.64.0';
logger.trace(`Docker container versions, services: ${process.env['NETWORK_NODE_IMAGE_TAG']}, mirror: ${process.env['MIRROR_IMAGE_TAG']}`);


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

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

//This is temporary solution
console.log('Installing local node...');
shell.exec(`npm install @hashgraph/hedera-local && hedera stop`);

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

console.log('Start local node');
shell.exec(`hedera start -d`);
console.log('Hedera Hashgraph local node env started');
}

function runLocalRelay() {
Expand Down
Loading