Skip to content

Commit babb356

Browse files
AlfredoG87ebadiere
andauthored
HotFix to allow Metamask to unblock Send Token Flow (#1936)
* 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 <[email protected]> * 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 <[email protected]> * increasing delay from 3 to 5s Signed-off-by: Alfredo Gutierrez <[email protected]> * adding a delay of 5s after eth_sendRawTransaction Signed-off-by: Alfredo Gutierrez <[email protected]> --------- Signed-off-by: Alfredo Gutierrez <[email protected]> --------- Signed-off-by: Alfredo Gutierrez <[email protected]> Co-authored-by: Eric Badiere <[email protected]>
1 parent bdb6d28 commit babb356

File tree

5 files changed

+40
-11
lines changed

5 files changed

+40
-11
lines changed

packages/server/src/server.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,11 @@ app.useRpc('eth_blockNumber', async () => {
281281
* returns: Gas used - hex encoded integer
282282
*/
283283
app.useRpc('eth_estimateGas', async (params: any) => {
284+
// HotFix for Metamask sending `0x` on data param
285+
if (params?.[0]?.data === '0x') {
286+
params[0].data = null;
287+
}
288+
284289
return logAndHandleResponse('eth_estimateGas', params, (requestId) =>
285290
relay.eth().estimateGas(params?.[0], params?.[1], requestId),
286291
);

packages/server/tests/acceptance/htsPrecompile/tokenCreate.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,6 @@ describe('@tokencreate HTS Precompile Token Create Acceptance Tests', async func
106106
requestId,
107107
);
108108

109-
// allow mirror node a 2 full record stream write windows (2 sec) and a buffer to persist setup details
110-
await new Promise((r) => setTimeout(r, 5000));
111-
await mirrorNode.get(`/accounts/${accounts[0].accountId}`, requestId);
112-
await mirrorNode.get(`/accounts/${accounts[1].accountId}`, requestId);
113-
await mirrorNode.get(`/accounts/${accounts[2].accountId}`, requestId);
114-
115109
HTSTokenContractAddress = await createHTSToken();
116110
NftHTSTokenContractAddress = await createNftHTSToken();
117111
HTSTokenWithCustomFeesContractAddress = await createHTSTokenWithCustomFees();
@@ -123,6 +117,9 @@ describe('@tokencreate HTS Precompile Token Create Acceptance Tests', async func
123117
mainContractOwner = mainContract;
124118
mainContractReceiverWalletFirst = mainContract.connect(accounts[1].wallet);
125119
mainContractReceiverWalletSecond = mainContract.connect(accounts[2].wallet);
120+
121+
// wait for mirror node to catch up before running tests
122+
await new Promise((r) => setTimeout(r, 5000));
126123
});
127124

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

132129
async function deploymainContract(signer) {
133130
const mainFactory = new ethers.ContractFactory(TokenCreateJson.abi, TokenCreateJson.bytecode, signer);
134-
const mainContract = await mainFactory.deploy(Constants.GAS.LIMIT_10_000_000);
131+
const mainContract = await mainFactory.deploy(await Utils.gasOptions(requestId, 15_000_000));
135132
await mainContract.waitForDeployment();
136133

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

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

545+
// delay
546+
await new Promise((r) => setTimeout(r, 5000));
547+
548548
expect(await NFTokenContract.balanceOf(mainContract.target)).to.equal(BigInt(1));
549549
expect(await NFTokenContract.balanceOf(accounts[1].wallet.address)).to.equal(BigInt(0));
550550
expect(await NFTokenContract.balanceOf(accounts[2].wallet.address)).to.equal(BigInt(0));
@@ -569,7 +569,7 @@ describe('@tokencreate HTS Precompile Token Create Acceptance Tests', async func
569569
NftSerialNumber,
570570
Constants.GAS.LIMIT_1_000_000,
571571
);
572-
await new Promise((r) => setTimeout(r, 2000));
572+
await new Promise((r) => setTimeout(r, 5000));
573573
expect(await NFTokenContract.balanceOf(mainContract.target)).to.equal(BigInt(0));
574574
expect(await NFTokenContract.balanceOf(accounts[1].wallet.address)).to.equal(BigInt(1));
575575

packages/server/tests/acceptance/rpc_batch1.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,7 @@ describe('@api-batch-1 RPC Server Acceptance Tests', function () {
771771
const transactionHash = await relay.sendRawTransaction(signedTx, requestId);
772772
// Since the transactionId is not available in this context
773773
// Wait for the transaction to be processed and imported in the mirror node with axios-retry
774+
await new Promise((r) => setTimeout(r, 5000));
774775
await mirrorNode.get(`/contracts/results/${transactionHash}`, requestId);
775776

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

912913
// Since the transactionId is not available in this context
913914
// Wait for the transaction to be processed and imported in the mirror node with axios-retry
915+
await new Promise((r) => setTimeout(r, 5000));
916+
914917
await mirrorNode.get(`/contracts/results/${transactionHash}`, requestId);
915918
const receiverEndBalance = await relay.getBalance(mirrorContract.evm_address, 'latest', requestId);
916919
const balanceChange = receiverEndBalance - receiverInitialBalance;

packages/server/tests/acceptance/rpc_batch2.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () {
133133

134134
this.beforeAll(async () => {
135135
basicContract = await servicesNode.deployContract(basicContractJson);
136+
// delay
137+
await new Promise((r) => setTimeout(r, 5000));
136138
});
137139

138140
it('@release should execute "eth_estimateGas"', async function () {
@@ -311,6 +313,25 @@ describe('@api-batch-2 RPC Server Acceptance Tests', function () {
311313
requestId,
312314
);
313315
});
316+
317+
it('should execute "eth_estimateGas" with data as 0x instead of null', async function () {
318+
const res = await relay.call(
319+
RelayCalls.ETH_ENDPOINTS.ETH_ESTIMATE_GAS,
320+
[
321+
{
322+
from: '0x114f60009ee6b84861c0cdae8829751e517bc4d7',
323+
to: '0xae410f34f7487e2cd03396499cebb09b79f45d6e',
324+
value: '0xa688906bd8b00000',
325+
gas: '0xd97010',
326+
data: '0x',
327+
},
328+
],
329+
requestId,
330+
);
331+
expect(res).to.contain('0x');
332+
expect(res).to.not.be.equal('0x');
333+
expect(res).to.not.be.equal('0x0');
334+
});
314335
});
315336

316337
describe('eth_gasPrice', async function () {

packages/server/tests/acceptance/ws/subscribe.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ describe('@web-socket Acceptance Tests', async function () {
145145

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

148-
expect(pings).to.eq(3);
148+
expect(pings).to.greaterThanOrEqual(2);
149149
});
150150

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

828-
await new Promise((resolve) => setTimeout(resolve, 3000));
828+
await new Promise((resolve) => setTimeout(resolve, 5000));
829829

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

0 commit comments

Comments
 (0)