Skip to content

Commit

Permalink
feat: stabilize flaky tests (#676)
Browse files Browse the repository at this point in the history
* chore: fix tests

Signed-off-by: nikolay <[email protected]>

* chore: edit assignments.js

Signed-off-by: nikolay <[email protected]>

* chore: edit panic tests

Signed-off-by: nikolay <[email protected]>

* chore: fix tests

Signed-off-by: nikolay <[email protected]>

* chore: fix redirect for token

Signed-off-by: nikolay <[email protected]>

* chore: fix tests

Signed-off-by: nikolay <[email protected]>

* chore: add deployment receipts

Signed-off-by: nikolay <[email protected]>

* chore: edit tests

Signed-off-by: nikolay <[email protected]>

---------

Signed-off-by: nikolay <[email protected]>
  • Loading branch information
natanasow authored Feb 20, 2024
1 parent 1d07283 commit 19009d3
Show file tree
Hide file tree
Showing 25 changed files with 99 additions and 80 deletions.

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions artifacts/contracts/hts-precompile/KeyHelper.sol/Bits.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"contractName": "Bits",
"sourceName": "contracts/hts-precompile/KeyHelper.sol",
"abi": [],
"bytecode": "0x60566037600b82828239805160001a607314602a57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea264697066735822122067216e15474e7ff5de36fce2f257ef9e1b96d81f64d66fb191e998216210fb4064736f6c63430008140033",
"deployedBytecode": "0x73000000000000000000000000000000000000000030146080604052600080fdfea264697066735822122067216e15474e7ff5de36fce2f257ef9e1b96d81f64d66fb191e998216210fb4064736f6c63430008140033",
"bytecode": "0x60566037600b82828239805160001a607314602a57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea26469706673582212205e8a9bfe14233a3ad27aad478528398893989a80c4dd029edb83dd658a4cba2364736f6c63430008140033",
"deployedBytecode": "0x73000000000000000000000000000000000000000030146080604052600080fdfea26469706673582212205e8a9bfe14233a3ad27aad478528398893989a80c4dd029edb83dd658a4cba2364736f6c63430008140033",
"linkReferences": {},
"deployedLinkReferences": {}
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
"type": "address"
}
],
"name": "delegatecallOnNoneExistingAccount",
"name": "delegatecallOnNonExistingAccount",
"outputs": [
{
"internalType": "bool",
Expand All @@ -98,7 +98,7 @@
"type": "address"
}
],
"name": "staticcallOnNoneExistingAccount",
"name": "staticcallOnNonExistingAccount",
"outputs": [
{
"internalType": "bool",
Expand All @@ -110,8 +110,8 @@
"type": "function"
}
],
"bytecode": "0x608060405234801561001057600080fd5b5060405161038638038061038683398101604081905261002f91610054565b600080546001600160a01b0319166001600160a01b0392909216919091179055610084565b60006020828403121561006657600080fd5b81516001600160a01b038116811461007d57600080fd5b9392505050565b6102f3806100936000396000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c806304fa55251461005c57806338750ce41461008457806370a082311461008457806394f6a1a0146100ad578063fb6641ba146100c0575b600080fd5b61006f61006a36600461025e565b6100d3565b60405190151581526020015b60405180910390f35b61009f61009236600461025e565b6001600160a01b03163190565b60405190815260200161007b565b61006f6100bb36600461025e565b610162565b61006f6100ce36600461025e565b6101e0565b60408051600481526024810182526020810180516001600160e01b0316630ee642d760e11b179052905160009182916001600160a01b038516916101169161028e565b6000604051808303816000865af19150503d8060008114610153576040519150601f19603f3d011682016040523d82523d6000602084013e610158565b606091505b5090949350505050565b60408051600481526024810182526020810180516001600160e01b0316630ee642d760e11b179052905160009182916001600160a01b038516916101a59161028e565b600060405180830381855af49150503d8060008114610153576040519150601f19603f3d011682016040523d82523d6000602084013e610158565b60408051600481526024810182526020810180516001600160e01b0316630ee642d760e11b179052905160009182916001600160a01b038516916102239161028e565b600060405180830381855afa9150503d8060008114610153576040519150601f19603f3d011682016040523d82523d6000602084013e610158565b60006020828403121561027057600080fd5b81356001600160a01b038116811461028757600080fd5b9392505050565b6000825160005b818110156102af5760208186018101518583015201610295565b50600092019182525091905056fea264697066735822122094369592fbdcfe04dac899899285101d38642dd7c19dc7025a3dd649b0d86c0064736f6c63430008140033",
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100575760003560e01c806304fa55251461005c57806338750ce41461008457806370a082311461008457806394f6a1a0146100ad578063fb6641ba146100c0575b600080fd5b61006f61006a36600461025e565b6100d3565b60405190151581526020015b60405180910390f35b61009f61009236600461025e565b6001600160a01b03163190565b60405190815260200161007b565b61006f6100bb36600461025e565b610162565b61006f6100ce36600461025e565b6101e0565b60408051600481526024810182526020810180516001600160e01b0316630ee642d760e11b179052905160009182916001600160a01b038516916101169161028e565b6000604051808303816000865af19150503d8060008114610153576040519150601f19603f3d011682016040523d82523d6000602084013e610158565b606091505b5090949350505050565b60408051600481526024810182526020810180516001600160e01b0316630ee642d760e11b179052905160009182916001600160a01b038516916101a59161028e565b600060405180830381855af49150503d8060008114610153576040519150601f19603f3d011682016040523d82523d6000602084013e610158565b60408051600481526024810182526020810180516001600160e01b0316630ee642d760e11b179052905160009182916001600160a01b038516916102239161028e565b600060405180830381855afa9150503d8060008114610153576040519150601f19603f3d011682016040523d82523d6000602084013e610158565b60006020828403121561027057600080fd5b81356001600160a01b038116811461028757600080fd5b9392505050565b6000825160005b818110156102af5760208186018101518583015201610295565b50600092019182525091905056fea264697066735822122094369592fbdcfe04dac899899285101d38642dd7c19dc7025a3dd649b0d86c0064736f6c63430008140033",
"bytecode": "0x608060405234801561001057600080fd5b5060405161038638038061038683398101604081905261002f91610054565b600080546001600160a01b0319166001600160a01b0392909216919091179055610084565b60006020828403121561006657600080fd5b81516001600160a01b038116811461007d57600080fd5b9392505050565b6102f3806100936000396000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c806304fa55251461005c57806338750ce41461008457806370a08231146100845780637688ef3a146100ad578063ac8ff975146100c0575b600080fd5b61006f61006a36600461025e565b6100d3565b60405190151581526020015b60405180910390f35b61009f61009236600461025e565b6001600160a01b03163190565b60405190815260200161007b565b61006f6100bb36600461025e565b610162565b61006f6100ce36600461025e565b6101e0565b60408051600481526024810182526020810180516001600160e01b0316630ee642d760e11b179052905160009182916001600160a01b038516916101169161028e565b6000604051808303816000865af19150503d8060008114610153576040519150601f19603f3d011682016040523d82523d6000602084013e610158565b606091505b5090949350505050565b60408051600481526024810182526020810180516001600160e01b0316630ee642d760e11b179052905160009182916001600160a01b038516916101a59161028e565b600060405180830381855afa9150503d8060008114610153576040519150601f19603f3d011682016040523d82523d6000602084013e610158565b60408051600481526024810182526020810180516001600160e01b0316630ee642d760e11b179052905160009182916001600160a01b038516916102239161028e565b600060405180830381855af49150503d8060008114610153576040519150601f19603f3d011682016040523d82523d6000602084013e610158565b60006020828403121561027057600080fd5b81356001600160a01b038116811461028757600080fd5b9392505050565b6000825160005b818110156102af5760208186018101518583015201610295565b50600092019182525091905056fea26469706673582212203c6153cffa6f0bfdee9f6c3d65b45af1d2aebb38adc9b9384a2852c52f3dd2ac64736f6c63430008140033",
"deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100575760003560e01c806304fa55251461005c57806338750ce41461008457806370a08231146100845780637688ef3a146100ad578063ac8ff975146100c0575b600080fd5b61006f61006a36600461025e565b6100d3565b60405190151581526020015b60405180910390f35b61009f61009236600461025e565b6001600160a01b03163190565b60405190815260200161007b565b61006f6100bb36600461025e565b610162565b61006f6100ce36600461025e565b6101e0565b60408051600481526024810182526020810180516001600160e01b0316630ee642d760e11b179052905160009182916001600160a01b038516916101169161028e565b6000604051808303816000865af19150503d8060008114610153576040519150601f19603f3d011682016040523d82523d6000602084013e610158565b606091505b5090949350505050565b60408051600481526024810182526020810180516001600160e01b0316630ee642d760e11b179052905160009182916001600160a01b038516916101a59161028e565b600060405180830381855afa9150503d8060008114610153576040519150601f19603f3d011682016040523d82523d6000602084013e610158565b60408051600481526024810182526020810180516001600160e01b0316630ee642d760e11b179052905160009182916001600160a01b038516916102239161028e565b600060405180830381855af49150503d8060008114610153576040519150601f19603f3d011682016040523d82523d6000602084013e610158565b60006020828403121561027057600080fd5b81356001600160a01b038116811461028757600080fd5b9392505050565b6000825160005b818110156102af5760208186018101518583015201610295565b50600092019182525091905056fea26469706673582212203c6153cffa6f0bfdee9f6c3d65b45af1d2aebb38adc9b9384a2852c52f3dd2ac64736f6c63430008140033",
"linkReferences": {},
"deployedLinkReferences": {}
}
2 changes: 1 addition & 1 deletion contracts/hts-precompile/HederaTokenService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,6 @@ abstract contract HederaTokenService {
);

emit CallResponseEvent(success, result);
(responseCode, response) = success ? abi.decode(result, (int32, bytes)) : (HederaResponseCodes.UNKNOWN, bytes(""));
(responseCode, response) = success ? (HederaResponseCodes.SUCCESS, result) : (HederaResponseCodes.UNKNOWN, bytes(""));
}
}
6 changes: 2 additions & 4 deletions test/discrepancies/Nonce.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ describe('@discrepancies - Nonce Test Suite', async () => {
expectNonIncrementedNonce(snBefore, mnBefore, snAfter, mnAfter);
});

// depends on https://github.com/hashgraph/hedera-smart-contracts/issues/659
xit('should not update nonce when offered gas price and allowance are zero handler check failed', async function () {
it('should not update nonce when offered gas price and allowance are zero handler check failed', async function () {
const snBefore = await getServicesNonce(signers[0].address);
const mnBefore = await getMirrorNodeNonce(signers[0].address);

Expand Down Expand Up @@ -139,8 +138,7 @@ describe('@discrepancies - Nonce Test Suite', async () => {
expectNonIncrementedNonce(snBefore, mnBefore, snAfter, mnAfter);
});

// depends on https://github.com/hashgraph/hedera-smart-contracts/issues/659
xit('should not update nonce when offered gas price is less than current and gas allowance is less than remaining fee handler check failed', async function () {
it('should not update nonce when offered gas price is less than current and gas allowance is less than remaining fee handler check failed', async function () {
const snBefore = await getServicesNonce(signers[0].address);
const mnBefore = await getMirrorNodeNonce(signers[0].address);

Expand Down
1 change: 0 additions & 1 deletion test/hip-583/HIP583.js
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,6 @@ describe('HIP583 Test Suite - Ethereum Transfer TX via Precompile', function ()
await signer.sendTransaction({
to: hollowWallet.address,
value: ethers.parseEther('100'),
value: ethers.parseEther('30'),
gasLimit: 1_000_000,
});
await utils.updateAccountKeysViaHapi(
Expand Down
21 changes: 11 additions & 10 deletions test/hts-precompile/redirect-for-token.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('RedirectForToken Test Suite', function () {

const parseCallResponseEventData = async (tx) => {
return (await tx.wait()).logs.filter(
(e) => e.fragment.name === Constants.Events.CallResponseEvent
(e) => e?.fragment?.name === Constants.Events.CallResponseEvent
)[0].args;
};

Expand Down Expand Up @@ -198,7 +198,7 @@ describe('RedirectForToken Test Suite', function () {
Constants.Path.ERC20Mock,
tokenAddress
);
await erc20.transfer(await tokenCreateContract.getAddress(), amount);
await (await erc20.transfer(await tokenCreateContract.getAddress(), amount)).wait();

const balanceBefore = await erc20.balanceOf(signers[1].address);

Expand All @@ -215,27 +215,27 @@ describe('RedirectForToken Test Suite', function () {

const balanceAfter = await erc20.balanceOf(signers[1].address);
expect(balanceBefore).to.not.eq(balanceAfter);
expect(balanceAfter).to.eq(balanceBefore + amount);
expect(balanceAfter).to.eq(balanceBefore + BigInt(amount));
});

it('should be able to execute transferFrom(address,address,uint256)', async function () {
const erc20 = await ethers.getContractAt(
Constants.Path.ERC20Mock,
tokenAddress
);
await erc20.transfer(await tokenCreateContract.getAddress(), amount);
await (await erc20.transfer(await tokenCreateContract.getAddress(), amount)).wait();

const tokenCreateContractBefore = await erc20.balanceOf(
await tokenCreateContract.getAddress()
);
const balanceBefore = await erc20.balanceOf(signers[1].address);

await tokenCreateContract.approvePublic(
await (await tokenCreateContract.approvePublic(
tokenAddress,
await tokenCreateContract.getAddress(),
amount,
Constants.GAS_LIMIT_1_000_000
);
)).wait();

const encodedFunc = IERC20.encodeFunctionData(
'transferFrom(address,address,uint256)',
Expand All @@ -246,15 +246,16 @@ describe('RedirectForToken Test Suite', function () {
encodedFunc,
Constants.GAS_LIMIT_1_000_000
);
const tokenCreateContractAfter = await erc20.balanceOf(
await tokenCreateContract.getAddress()
);
const [success] = await parseCallResponseEventData(tx);
expect(success).to.eq(true);

const tokenCreateContractAfter = await erc20.balanceOf(
await tokenCreateContract.getAddress()
);

const balanceAfter = await erc20.balanceOf(signers[1].address);
expect(balanceBefore).to.not.eq(balanceAfter);
expect(tokenCreateContractAfter).to.eq(tokenCreateContractBefore - amount);
expect(tokenCreateContractAfter).to.eq(tokenCreateContractBefore - BigInt(amount));
expect(balanceAfter).to.eq(parseInt(balanceBefore) + parseInt(amount));
});
});
4 changes: 4 additions & 0 deletions test/openzeppelin/ERC-1967-Upgrade/Vote.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,19 @@ describe('@OZERC1967Upgrade Upgradable Vote Test Suite', () => {
Constants.Contract.VoteV1
);
voteV1 = await VoteV1Fac.deploy();
await voteV1.waitForDeployment();

const VoteV2Fac = await ethers.getContractFactory(
Constants.Contract.VoteV2
);
voteV2 = await VoteV2Fac.deploy();
await voteV2.waitForDeployment();

const VoteProxyFac = await ethers.getContractFactory(
Constants.Contract.VoteProxy
);
voteProxy = await VoteProxyFac.deploy(await voteV1.getAddress());
await voteProxy.waitForDeployment();
});

describe('Proxy Contract tests', () => {
Expand Down Expand Up @@ -201,6 +204,7 @@ describe('@OZERC1967Upgrade Upgradable Vote Test Suite', () => {
EMPTY_DATA,
GAS_LIMIT_1_000_000
);
await tx.wait();

proxiedVoteV2 = new ethers.Contract(
await voteProxy.getAddress(),
Expand Down
1 change: 1 addition & 0 deletions test/openzeppelin/pausable/pausable.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('@OZPausable Test Suite', function () {
Constants.Contract.PausableTest
);
contract = await factory.deploy();
await contract.waitForDeployment();
});

it('should BE able to call function "setPausedMessage" with "whenNotPaused" modifier when unpaused', async function () {
Expand Down
9 changes: 5 additions & 4 deletions test/openzeppelin/uups-upgradable/Vault.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('@OZUUPSUpgradable Upgradable Vaults Test Suite', () => {
vaultV1 = await upgrades.deployProxy(VaultV1, {
kind: 'uups',
});
await vaultV1.waitForDeployment();
});

it('V1: Should deploy the proxy', async () => {
Expand All @@ -46,15 +47,15 @@ describe('@OZUUPSUpgradable Upgradable Vaults Test Suite', () => {
});

it('V1: Should deposit Hbar into vaultV1', async () => {
await vaultV1.deposit({ value: DEPOSIT_AMOUNT });
await (await vaultV1.deposit({ value: DEPOSIT_AMOUNT })).wait();

const totalBalance = await vaultV1.totalBalance();

expect(totalBalance).to.eq(DEPOSIT_AMOUNT / TINY_BAR_TO_WEI_COEF);
});

it('V1: Should allow owner to withdraw an amount of Hbar', async () => {
await vaultV1.deposit({ value: DEPOSIT_AMOUNT });
await (await vaultV1.deposit({ value: DEPOSIT_AMOUNT })).wait();
const WITHDRAW_AMOUNT = ethers.parseEther('1.0') / TINY_BAR_TO_WEI_COEF;

const tx = await vaultV1.withdraw(WITHDRAW_AMOUNT);
Expand Down Expand Up @@ -114,15 +115,15 @@ describe('@OZUUPSUpgradable Upgradable Vaults Test Suite', () => {
});

it('V2: Should deposit Hbar into vaultV2', async () => {
await vaultV2.deposit({ value: DEPOSIT_AMOUNT });
await (await vaultV2.deposit({ value: DEPOSIT_AMOUNT })).wait();

const totalBalance = await vaultV1.totalBalance();

expect(totalBalance).to.eq(DEPOSIT_AMOUNT / TINY_BAR_TO_WEI_COEF);
});

it('V2: Should allow the rightful beneficiary to withdraw an amount of Hbar', async () => {
await vaultV2.deposit({ value: DEPOSIT_AMOUNT });
await (await vaultV2.deposit({ value: DEPOSIT_AMOUNT })).wait();

const WITHDRAW_AMOUNT = ethers.parseEther('1.0') / TINY_BAR_TO_WEI_COEF;

Expand Down
6 changes: 4 additions & 2 deletions test/proxy-upgrade/proxyUpgradeContracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ describe('Proxy Upgrade Contracts Test Suite', function () {
kind: 'uups',
initializer: 'initialize',
});
await proxy.waitForDeployment();

return proxy;
}
Expand Down Expand Up @@ -304,6 +305,7 @@ describe('Proxy Upgrade Contracts Test Suite', function () {
kind: 'uups',
initializer: 'initialize',
});
await proxy.waitForDeployment();

return proxy;
}
Expand All @@ -324,7 +326,7 @@ describe('Proxy Upgrade Contracts Test Suite', function () {
//increment counter
{
const counterBefore = await proxyContract.count();
await proxyContract.increment();
await (await proxyContract.increment()).wait();
const counterAfter = await proxyContract.count();
expect(counterAfter, 'Asserting counter increment').to.be.greaterThan(
counterBefore
Expand All @@ -334,7 +336,7 @@ describe('Proxy Upgrade Contracts Test Suite', function () {
//decrement counter
{
const counterBefore = await proxyContract.count();
await proxyContract.decrement();
await (await proxyContract.decrement()).wait();
const counterAfter = await proxyContract.count();
expect(
counterAfter,
Expand Down
8 changes: 4 additions & 4 deletions test/solidity/account/nonExisting.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('@solidityequiv1 Solidity Account Non Existing Test Suite', function ()

it('should confirm `delegatecall` on a non existing account', async function () {
try {
const tx = await fakeContract.delegatecallOnNoneExistingAccount(
const tx = await fakeContract.delegatecallOnNonExistingAccount(
randomAddress
);
await tx.wait();
Expand All @@ -79,7 +79,7 @@ describe('@solidityequiv1 Solidity Account Non Existing Test Suite', function ()
});

it('should confirm `delegatecall` on a non existing account internal', async function () {
const tx = await contract.delegatecallOnNoneExistingAccount(
const tx = await contract.delegatecallOnNonExistingAccount(
randomAddress
);
const rec = await tx.wait();
Expand All @@ -88,7 +88,7 @@ describe('@solidityequiv1 Solidity Account Non Existing Test Suite', function ()

it('should confirm `staticcall` on a non existing account', async function () {
try {
const tx = await fakeContract.staticcallOnNoneExistingAccount(
const tx = await fakeContract.staticcallOnNonExistingAccount(
randomAddress
);
await tx.wait();
Expand All @@ -100,7 +100,7 @@ describe('@solidityequiv1 Solidity Account Non Existing Test Suite', function ()
});

it('should confirm `staticcall` on a non existing account internal', async function () {
const tx = await contract.staticcallOnNoneExistingAccount(randomAddress);
const tx = await contract.staticcallOnNonExistingAccount(randomAddress);
expect(tx).to.equal(true);
});

Expand Down
2 changes: 1 addition & 1 deletion test/solidity/assignments/assignments.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('@solidityequiv1 Assignments Test Suite', function () {
// here we are testing that if a parameter is assigned to memory a copy will be created
// and the original object wont be changed
// while if it is in storage and only referenced we expect it to change
await contractReferenceTypes.testAssignmentOfReferenceTypes();
await (await contractReferenceTypes.testAssignmentOfReferenceTypes()).wait();
const result = await contractReferenceTypes.getSomeArray();
expect(result).to.deep.equal([
BigInt(1),
Expand Down
2 changes: 1 addition & 1 deletion test/solidity/block/BlockInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('@solidityequiv1 BlockInfo Test Suite', function () {

it('should get the block gas limit', async function () {
const gasLimit = await blockInfo.getBlockGasLimit();
expect(gasLimit).to.equal(400000);
expect(gasLimit).to.equal(15000000);
});

it('should get the block number', async function () {
Expand Down
Loading

0 comments on commit 19009d3

Please sign in to comment.