Skip to content
This repository has been archived by the owner on Jun 12, 2023. It is now read-only.

Commit

Permalink
fix: gaslimit (#254)
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomrdias authored Mar 27, 2023
1 parent 70e9cab commit 067fce8
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/Chainsafe/filsnap.git"
},
"source": {
"shasum": "8Vx7jaoJt4mO71SjaNMmmlINtDrBOS6mVxskBxMw4sg=",
"shasum": "Z7lh6iD1yjfKES/WutUyxepg5Dgp8Xjo3kivsz9vpwc=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
4 changes: 1 addition & 3 deletions packages/snap/src/rpc/estimateMessageGas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ export async function estimateMessageGas(
method: 0, // code for basic transaction
nonce: 0, // dummy nonce just for gas calculation
};
// estimate gas usage
const gasLimit = await api.gasEstimateGasLimit(message, null);
// set max fee to 0.1 FIL if not set
const maxFeeAttoFil = maxFee
? maxFee
Expand All @@ -37,7 +35,7 @@ export async function estimateMessageGas(
);
return {
gasfeecap: messageEstimate.GasFeeCap,
gaslimit: gasLimit,
gaslimit: messageEstimate.GasLimit,
gaspremium: messageEstimate.GasPremium,
maxfee: maxFeeAttoFil,
};
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/src/rpc/signMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ export async function signMessage(
message.gasfeecap === "0" &&
message.gaspremium === "0"
) {
message.gaslimit = await api.gasEstimateGasLimit(message, null);
const messageEstimate = await api.gasEstimateMessageGas(
message,
{ MaxFee: "0" },
null
);
message.gaslimit = messageEstimate.GasLimit;
message.gaspremium = messageEstimate.GasPremium;
message.gasfeecap = messageEstimate.GasFeeCap;
}
Expand Down
6 changes: 2 additions & 4 deletions packages/snap/test/unit/rpc/signMessage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ describe("Test rpc handler function: signMessage", function () {
walletStub.prepareFoKeyPair();

apiStub.mpoolGetNonce.returns("0");
apiStub.gasEstimateGasLimit.returns(1000);
apiStub.gasEstimateMessageGas.returns({
GasPremium: "10",
GasFeeCap: "10",
GasLimit: 1000,
});

const response = await signMessage(walletStub, apiStub, messageRequest);
Expand All @@ -61,7 +61,6 @@ describe("Test rpc handler function: signMessage", function () {
expect(walletStub.rpcStubs.snap_getBip44Entropy).to.have.been.calledOnce;
expect(walletStub.rpcStubs.snap_manageState).to.have.been.calledOnce;
expect(apiStub.mpoolGetNonce).to.have.been.calledOnce;
expect(apiStub.gasEstimateGasLimit).to.have.been.calledOnce;
expect(apiStub.gasEstimateMessageGas).to.have.been.calledOnce;
expect(response.signedMessage.message).to.be.deep.eq(fullMessage);
expect(response.signedMessage.signature.data).to.not.be.empty;
Expand Down Expand Up @@ -103,10 +102,10 @@ describe("Test rpc handler function: signMessage", function () {
walletStub.rpcStubs.snap_confirm.resolves(true);
walletStub.prepareFoKeyPair();
apiStub.mpoolGetNonce.returns("0");
apiStub.gasEstimateGasLimit.returns(1000);
apiStub.gasEstimateMessageGas.returns({
GasFeeCap: "10",
GasPremium: "10",
GasLimit: 1000,
});

const messageRequestWithCustomParams: MessageRequest = {
Expand All @@ -123,7 +122,6 @@ describe("Test rpc handler function: signMessage", function () {
expect(walletStub.rpcStubs.snap_getBip44Entropy).to.have.been.calledOnce;
expect(walletStub.rpcStubs.snap_manageState).to.have.been.calledOnce;
expect(apiStub.mpoolGetNonce).to.have.been.calledOnce;
expect(apiStub.gasEstimateGasLimit).to.have.been.calledOnce;
expect(apiStub.gasEstimateMessageGas).to.have.been.calledOnce;
expect(response.signedMessage.message).to.be.deep.eq(paramsMessage);
expect(response.signedMessage.signature.data).to.not.be.empty;
Expand Down

0 comments on commit 067fce8

Please sign in to comment.