-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update acceptance tests to use new signatures. Create new acceptance… (…
…#510) * update acceptance tests to use new signatures. Create new acceptance test to exercise old create token function signatures Signed-off-by: lukelee-sl <luke.lee@swirldslabs.com> * increase fees for account Signed-off-by: lukelee-sl <luke.lee@swirldslabs.com> * update description of HTS Precompile V1 test Signed-off-by: lukelee-sl <luke.lee@swirldslabs.com> * adjust fees Signed-off-by: lukelee-sl <luke.lee@swirldslabs.com> * increase fee for v1 acceptance tests Signed-off-by: lukelee-sl <luke.lee@swirldslabs.com> * increase fee for v1 acceptance tests once more Signed-off-by: lukelee-sl <luke.lee@swirldslabs.com> * address review comments Signed-off-by: lukelee-sl <luke.lee@swirldslabs.com> * refactor tests Signed-off-by: lukelee-sl <luke.lee@swirldslabs.com> Signed-off-by: lukelee-sl <luke.lee@swirldslabs.com>
- Loading branch information
1 parent
c85f187
commit 44c4164
Showing
19 changed files
with
5,629 additions
and
48 deletions.
There are no files selected for viewing
148 changes: 148 additions & 0 deletions
148
packages/server/tests/acceptance/htsPrecompile_v1.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/*- | ||
* | ||
* Hedera JSON RPC Relay | ||
* | ||
* Copyright (C) 2022 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. | ||
* | ||
*/ | ||
|
||
// external resources | ||
import { solidity } from 'ethereum-waffle'; | ||
import chai, { expect } from 'chai'; | ||
|
||
chai.use(solidity); | ||
|
||
import { AliasAccount } from '../clients/servicesClient'; | ||
import { ethers } from 'ethers'; | ||
import ERC20MockJson from '../contracts/contracts_v1/ERC20Mock.json'; | ||
import BaseHTSJson from '../contracts/contracts_v1/BaseHTS.json'; | ||
|
||
|
||
describe('HTS Precompile V1 Acceptance Tests', async function () { | ||
this.timeout(240 * 1000); // 240 seconds | ||
const { servicesNode, relay } = global; | ||
|
||
const TX_SUCCESS_CODE = 22; | ||
|
||
const accounts: AliasAccount[] = []; | ||
let BaseHTSContractAddress; | ||
let HTSTokenContractAddress; | ||
let NftHTSTokenContractAddress; | ||
let baseHTSContract; | ||
let baseHTSContractOwner; | ||
let baseHTSContractReceiverWalletFirst; | ||
let baseHTSContractReceiverWalletSecond; | ||
let HTSTokenWithCustomFeesContractAddress; | ||
|
||
this.beforeAll(async () => { | ||
accounts[0] = await servicesNode.createAliasAccount(60, relay.provider); | ||
accounts[1] = await servicesNode.createAliasAccount(15, relay.provider); | ||
accounts[2] = await servicesNode.createAliasAccount(15, relay.provider); | ||
|
||
// alow mirror node a 2 full record stream write windows (2 sec) and a buffer to persist setup details | ||
await new Promise(r => setTimeout(r, 5000)); | ||
|
||
BaseHTSContractAddress = await deployBaseHTSContract(); | ||
baseHTSContract = new ethers.Contract(BaseHTSContractAddress, BaseHTSJson.abi, accounts[0].wallet); | ||
|
||
baseHTSContractOwner = baseHTSContract; | ||
baseHTSContractReceiverWalletFirst = baseHTSContract.connect(accounts[1].wallet); | ||
baseHTSContractReceiverWalletSecond = baseHTSContract.connect(accounts[2].wallet); | ||
}); | ||
|
||
async function deployBaseHTSContract() { | ||
const baseHTSFactory = new ethers.ContractFactory(BaseHTSJson.abi, BaseHTSJson.bytecode, accounts[0].wallet); | ||
const baseHTS = await baseHTSFactory.deploy({gasLimit: 10_000_000}); | ||
const { contractAddress } = await baseHTS.deployTransaction.wait(); | ||
|
||
return contractAddress; | ||
} | ||
|
||
async function createHTSToken() { | ||
const baseHTSContract = new ethers.Contract(BaseHTSContractAddress, BaseHTSJson.abi, accounts[0].wallet); | ||
const tx = await baseHTSContract.createFungibleTokenPublic(accounts[0].wallet.address, { | ||
value: ethers.BigNumber.from('10000000000000000000'), | ||
gasLimit: 1_000_000 | ||
}); | ||
const { tokenAddress } = (await tx.wait()).events.filter(e => e.event = 'CreatedToken')[0].args; | ||
|
||
return tokenAddress; | ||
} | ||
|
||
async function createNftHTSToken() { | ||
const baseHTSContract = new ethers.Contract(BaseHTSContractAddress, BaseHTSJson.abi, accounts[0].wallet); | ||
const tx = await baseHTSContract.createNonFungibleTokenPublic(accounts[0].wallet.address, { | ||
value: ethers.BigNumber.from('10000000000000000000'), | ||
gasLimit: 1_000_000 | ||
}); | ||
const { tokenAddress } = (await tx.wait()).events.filter(e => e.event = 'CreatedToken')[0].args; | ||
|
||
return tokenAddress; | ||
} | ||
|
||
async function createHTSTokenWithCustomFees() { | ||
const baseHTSContract = new ethers.Contract(BaseHTSContractAddress, BaseHTSJson.abi, accounts[0].wallet); | ||
const tx = await baseHTSContract.createFungibleTokenWithCustomFeesPublic(accounts[0].wallet.address, HTSTokenContractAddress, { | ||
value: ethers.BigNumber.from('20000000000000000000'), | ||
gasLimit: 1_000_000 | ||
}); | ||
const txReceipt = await tx.wait(); | ||
const { tokenAddress } = txReceipt.events.filter(e => e.event === 'CreatedToken')[0].args; | ||
|
||
return tokenAddress; | ||
} | ||
|
||
it('should create associate to a fungible token', async function() { | ||
HTSTokenContractAddress = await createHTSToken(); | ||
|
||
const txCO = await baseHTSContractOwner.associateTokenPublic(BaseHTSContractAddress, HTSTokenContractAddress, { gasLimit: 1_000_000 }); | ||
expect((await txCO.wait()).events.filter(e => e.event === 'ResponseCode')[0].args.responseCode).to.equal(TX_SUCCESS_CODE); | ||
|
||
const txRWF = await baseHTSContractReceiverWalletFirst.associateTokenPublic(accounts[1].wallet.address, HTSTokenContractAddress, { gasLimit: 1_000_000 }); | ||
expect((await txRWF.wait()).events.filter(e => e.event === 'ResponseCode')[0].args.responseCode).to.equal(TX_SUCCESS_CODE); | ||
|
||
const txRWS = await baseHTSContractReceiverWalletSecond.associateTokenPublic(accounts[2].wallet.address, HTSTokenContractAddress, { gasLimit: 1_000_000 }); | ||
expect((await txRWS.wait()).events.filter(e => e.event === 'ResponseCode')[0].args.responseCode).to.equal(TX_SUCCESS_CODE); | ||
}); | ||
|
||
it('should create and associate to an nft', async function() { | ||
NftHTSTokenContractAddress = await createNftHTSToken(); | ||
|
||
const txCO = await baseHTSContractOwner.associateTokenPublic(BaseHTSContractAddress, NftHTSTokenContractAddress, { gasLimit: 1_000_000 }); | ||
expect((await txCO.wait()).events.filter(e => e.event === 'ResponseCode')[0].args.responseCode).to.equal(TX_SUCCESS_CODE); | ||
|
||
const txRWF = await baseHTSContractReceiverWalletFirst.associateTokenPublic(accounts[1].wallet.address, NftHTSTokenContractAddress, { gasLimit: 1_000_000 }); | ||
expect((await txRWF.wait()).events.filter(e => e.event === 'ResponseCode')[0].args.responseCode).to.equal(TX_SUCCESS_CODE); | ||
|
||
const txRWS = await baseHTSContractReceiverWalletSecond.associateTokenPublic(accounts[2].wallet.address, NftHTSTokenContractAddress, { gasLimit: 1_000_000 }); | ||
expect((await txRWS.wait()).events.filter(e => e.event === 'ResponseCode')[0].args.responseCode).to.equal(TX_SUCCESS_CODE); | ||
}); | ||
|
||
it('should create and associate to a fungible token with custom fees', async function() { | ||
HTSTokenWithCustomFeesContractAddress = await createHTSTokenWithCustomFees(); | ||
|
||
const baseHTSContractOwner = new ethers.Contract(BaseHTSContractAddress, BaseHTSJson.abi, accounts[0].wallet); | ||
const txCO = await baseHTSContractOwner.associateTokenPublic(BaseHTSContractAddress, HTSTokenWithCustomFeesContractAddress, { gasLimit: 1_000_000 }); | ||
expect((await txCO.wait()).events.filter(e => e.event === 'ResponseCode')[0].args.responseCode).to.equal(TX_SUCCESS_CODE); | ||
|
||
const baseHTSContractReceiverWalletFirst = new ethers.Contract(BaseHTSContractAddress, BaseHTSJson.abi, accounts[1].wallet); | ||
const txRWF = await baseHTSContractReceiverWalletFirst.associateTokenPublic(accounts[1].wallet.address, HTSTokenWithCustomFeesContractAddress, { gasLimit: 1_000_000 }); | ||
expect((await txRWF.wait()).events.filter(e => e.event === 'ResponseCode')[0].args.responseCode).to.equal(TX_SUCCESS_CODE); | ||
|
||
const baseHTSContractReceiverWalletSecond = new ethers.Contract(BaseHTSContractAddress, BaseHTSJson.abi, accounts[2].wallet); | ||
const txRWS = await baseHTSContractReceiverWalletSecond.associateTokenPublic(accounts[2].wallet.address, HTSTokenWithCustomFeesContractAddress, { gasLimit: 1_000_000 }); | ||
expect((await txRWS.wait()).events.filter(e => e.event === 'ResponseCode')[0].args.responseCode).to.equal(TX_SUCCESS_CODE); | ||
}); | ||
}); |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.