Skip to content

Commit

Permalink
HotFix to allow Metamask to unblock Send Token Flow (#1936)
Browse files Browse the repository at this point in the history
* HotFix to allow Metamask to unblock Send Token Flow, since Metamask is sending `data` field as `0x` instead of not sending it.

Signed-off-by: Alfredo Gutierrez <alfredo@swirldslabs.com>

* Acceptance Tests TokenCreate Fix and Reliability Improvements (#1918)

* Increasing some delays on the acceptance tests that are the most flaky.
Changing web-socket ping verification to be 2 or more, since sometimes is 2 and other 3.
Isolating TokenCreate Test
Adding some delays right before calling balanceOf / eth_getBalance.
Adding some delays were needed
Reduce Flaky-ness Tests on rpc_batch1, rpc_batch2, tokenCreate and subscribe tests
Fixed Gas issue with TokenCreate Test.

Signed-off-by: Alfredo Gutierrez <alfredo@swirldslabs.com>

* increasing delay from 3 to 5s

Signed-off-by: Alfredo Gutierrez <alfredo@swirldslabs.com>

* adding a delay of 5s after eth_sendRawTransaction

Signed-off-by: Alfredo Gutierrez <alfredo@swirldslabs.com>

---------

Signed-off-by: Alfredo Gutierrez <alfredo@swirldslabs.com>

---------

Signed-off-by: Alfredo Gutierrez <alfredo@swirldslabs.com>
Co-authored-by: Eric Badiere <ebadiere@gmail.com>
  • Loading branch information
AlfredoG87 and ebadiere authored Nov 29, 2023
1 parent bdb6d28 commit babb356
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 11 deletions.
5 changes: 5 additions & 0 deletions packages/server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ app.useRpc('eth_blockNumber', async () => {
* returns: Gas used - hex encoded integer
*/
app.useRpc('eth_estimateGas', async (params: any) => {
// HotFix for Metamask sending `0x` on data param
if (params?.[0]?.data === '0x') {
params[0].data = null;
}

return logAndHandleResponse('eth_estimateGas', params, (requestId) =>
relay.eth().estimateGas(params?.[0], params?.[1], requestId),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,6 @@ describe('@tokencreate HTS Precompile Token Create Acceptance Tests', async func
requestId,
);

// allow 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));
await mirrorNode.get(`/accounts/${accounts[0].accountId}`, requestId);
await mirrorNode.get(`/accounts/${accounts[1].accountId}`, requestId);
await mirrorNode.get(`/accounts/${accounts[2].accountId}`, requestId);

HTSTokenContractAddress = await createHTSToken();
NftHTSTokenContractAddress = await createNftHTSToken();
HTSTokenWithCustomFeesContractAddress = await createHTSTokenWithCustomFees();
Expand All @@ -123,6 +117,9 @@ describe('@tokencreate HTS Precompile Token Create Acceptance Tests', async func
mainContractOwner = mainContract;
mainContractReceiverWalletFirst = mainContract.connect(accounts[1].wallet);
mainContractReceiverWalletSecond = mainContract.connect(accounts[2].wallet);

// wait for mirror node to catch up before running tests
await new Promise((r) => setTimeout(r, 5000));
});

this.beforeEach(async () => {
Expand All @@ -131,7 +128,7 @@ describe('@tokencreate HTS Precompile Token Create Acceptance Tests', async func

async function deploymainContract(signer) {
const mainFactory = new ethers.ContractFactory(TokenCreateJson.abi, TokenCreateJson.bytecode, signer);
const mainContract = await mainFactory.deploy(Constants.GAS.LIMIT_10_000_000);
const mainContract = await mainFactory.deploy(await Utils.gasOptions(requestId, 15_000_000));
await mainContract.waitForDeployment();

return mainContract.target;
Expand Down Expand Up @@ -403,7 +400,7 @@ describe('@tokencreate HTS Precompile Token Create Acceptance Tests', async func
amount,
Constants.GAS.LIMIT_1_000_000,
);
await new Promise((r) => setTimeout(r, 2000));
await new Promise((r) => setTimeout(r, 5000));
expect(await HTSTokenContract.balanceOf(accounts[1].wallet.address)).to.be.equal(amount);

{
Expand Down Expand Up @@ -545,6 +542,9 @@ describe('@tokencreate HTS Precompile Token Create Acceptance Tests', async func
.responseCode,
).to.equal(TX_SUCCESS_CODE);

// delay
await new Promise((r) => setTimeout(r, 5000));

expect(await NFTokenContract.balanceOf(mainContract.target)).to.equal(BigInt(1));
expect(await NFTokenContract.balanceOf(accounts[1].wallet.address)).to.equal(BigInt(0));
expect(await NFTokenContract.balanceOf(accounts[2].wallet.address)).to.equal(BigInt(0));
Expand All @@ -569,7 +569,7 @@ describe('@tokencreate HTS Precompile Token Create Acceptance Tests', async func
NftSerialNumber,
Constants.GAS.LIMIT_1_000_000,
);
await new Promise((r) => setTimeout(r, 2000));
await new Promise((r) => setTimeout(r, 5000));
expect(await NFTokenContract.balanceOf(mainContract.target)).to.equal(BigInt(0));
expect(await NFTokenContract.balanceOf(accounts[1].wallet.address)).to.equal(BigInt(1));

Expand Down
3 changes: 3 additions & 0 deletions packages/server/tests/acceptance/rpc_batch1.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () {
const transactionHash = await relay.sendRawTransaction(signedTx, requestId);
// Since the transactionId is not available in this context
// Wait for the transaction to be processed and imported in the mirror node with axios-retry
await new Promise((r) => setTimeout(r, 5000));
await mirrorNode.get(`/contracts/results/${transactionHash}`, requestId);

const receiverEndBalance = await relay.getBalance(mirrorContract.evm_address, 'latest', requestId);
Expand Down Expand Up @@ -911,6 +912,8 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () {

// Since the transactionId is not available in this context
// Wait for the transaction to be processed and imported in the mirror node with axios-retry
await new Promise((r) => setTimeout(r, 5000));

await mirrorNode.get(`/contracts/results/${transactionHash}`, requestId);
const receiverEndBalance = await relay.getBalance(mirrorContract.evm_address, 'latest', requestId);
const balanceChange = receiverEndBalance - receiverInitialBalance;
Expand Down
21 changes: 21 additions & 0 deletions packages/server/tests/acceptance/rpc_batch2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () {

this.beforeAll(async () => {
basicContract = await servicesNode.deployContract(basicContractJson);
// delay
await new Promise((r) => setTimeout(r, 5000));
});

it('@release should execute "eth_estimateGas"', async function () {
Expand Down Expand Up @@ -311,6 +313,25 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () {
requestId,
);
});

it('should execute "eth_estimateGas" with data as 0x instead of null', async function () {
const res = await relay.call(
RelayCalls.ETH_ENDPOINTS.ETH_ESTIMATE_GAS,
[
{
from: '0x114f60009ee6b84861c0cdae8829751e517bc4d7',
to: '0xae410f34f7487e2cd03396499cebb09b79f45d6e',
value: '0xa688906bd8b00000',
gas: '0xd97010',
data: '0x',
},
],
requestId,
);
expect(res).to.contain('0x');
expect(res).to.not.be.equal('0x');
expect(res).to.not.be.equal('0x0');
});
});

describe('eth_gasPrice', async function () {
Expand Down
4 changes: 2 additions & 2 deletions packages/server/tests/acceptance/ws/subscribe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ describe('@web-socket Acceptance Tests', async function () {

await new Promise((resolve) => setTimeout(resolve, 2500));

expect(pings).to.eq(3);
expect(pings).to.greaterThanOrEqual(2);
});

it('@release Socket server responds to the eth_chainId event', async function () {
Expand Down Expand Up @@ -825,7 +825,7 @@ describe('@web-socket Acceptance Tests', async function () {
const tx = await htsToken.transfer(htsAccounts[1].wallet.address, 1, Constants.GAS.LIMIT_1_000_000);
await tx.wait();

await new Promise((resolve) => setTimeout(resolve, 3000));
await new Promise((resolve) => setTimeout(resolve, 5000));

const balanceAfter = await htsToken.balanceOf(htsAccounts[1].wallet.address);
expect(balanceAfter.toString()).to.eq('1', 'token is successfully transferred');
Expand Down

0 comments on commit babb356

Please sign in to comment.