Skip to content

Commit

Permalink
Merge pull request #3400 from jorgemmsilva/fix/zero-fee-receive-reqs
Browse files Browse the repository at this point in the history
fix(zero-fees): allow to receive requests without on-chain funds
  • Loading branch information
jorgemmsilva authored May 8, 2024
2 parents 10b1ada + f98e7db commit 083907b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
2 changes: 1 addition & 1 deletion packages/chain/mempool/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ func (mpi *mempoolImpl) shouldAddOffledgerRequest(req isc.OffLedgerRequest) erro
governanceState := governance.NewStateAccess(mpi.chainHeadState)
chainOwner := governanceState.ChainOwnerID()
isGovRequest := req.SenderAccount().Equals(chainOwner) && req.CallTarget().Contract == governance.Contract.Hname()
if !isGovRequest || governanceState.DefaultGasPrice().Cmp(util.Big0) == 0 {
if !isGovRequest && governanceState.DefaultGasPrice().Cmp(util.Big0) != 0 {
return fmt.Errorf("no funds on chain")
}
}
Expand Down
39 changes: 25 additions & 14 deletions tools/cluster/tests/wasp-cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tests

import (
"context"
"crypto/ecdsa"
"encoding/json"
"fmt"
"io"
Expand All @@ -13,6 +14,7 @@ import (
"testing"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/samber/lo"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -68,7 +70,7 @@ func TestZeroGasFee(t *testing.T) {
committee, quorum := w.ArgCommitteeConfig(0)

// test chain deploy command
w.MustRun("chain", "deploy", "--chain="+chainName, committee, quorum, "--evm-chainid=1091", "--block-keep-amount=123", "--node=0")
w.MustRun("chain", "deploy", "--chain="+chainName, committee, quorum, "--block-keep-amount=123", "--node=0")
w.ActivateChainOnAllNodes(chainName, 0)
outs, err := w.Run("chain", "info", "--node=0", "--node=0")
require.NoError(t, err)
Expand All @@ -79,11 +81,15 @@ func TestZeroGasFee(t *testing.T) {
require.NoError(t, err)
require.Contains(t, outs, "Gas fee: gas units * (0/0)")

alternativeAddress := getAddress(w.MustRun("address", "--address-index=1"))
w.MustRun("send-funds", "-s", alternativeAddress, "base:1000000")
checkBalance(t, w.MustRun("balance", "--address-index=1"), 1000000)
t.Run("send arbitrary EVM tx without funds", func(t *testing.T) {
ethPvtKey, _ := newEthereumAccount()
sendDummyEVMTx(t, w, ethPvtKey)
})

t.Run("deposit directly to EVM", func(t *testing.T) {
alternativeAddress := getAddress(w.MustRun("address", "--address-index=1"))
w.MustRun("send-funds", "-s", alternativeAddress, "base:1000000")
checkBalance(t, w.MustRun("balance", "--address-index=1"), 1000000)
_, eth := newEthereumAccount()
w.MustRun("chain", "deposit", eth.String(), "base:1000000", "--node=0", "--address-index=1")
checkBalance(t, w.MustRun("chain", "balance", eth.String(), "--node=0"), 1000000)
Expand Down Expand Up @@ -826,25 +832,30 @@ func TestWaspCLIRegisterERC20NativeTokenOnRemoteChain(t *testing.T) {
require.Contains(t, strings.Join(out, "\n"), "Error: (empty)")
}

func TestEVMISCReceipt(t *testing.T) {
w := newWaspCLITest(t)
committee, quorum := w.ArgCommitteeConfig(0)
w.MustRun("chain", "deploy", "--chain=chain1", committee, quorum, "--node=0")
w.ActivateChainOnAllNodes("chain1", 0)
ethPvtKey, ethAddr := newEthereumAccount()
w.MustRun("chain", "deposit", ethAddr.String(), "base:100000000", "--node=0")

// send some arbitrary EVM tx
func sendDummyEVMTx(t *testing.T, w *WaspCLITest, ethPvtKey *ecdsa.PrivateKey) *types.Transaction {
gasPrice := gas.DefaultFeePolicy().DefaultGasPriceFullDecimals(parameters.L1().BaseToken.Decimals)
jsonRPCClient := NewEVMJSONRPClient(t, w.ChainID(0), w.Cluster, 0)
tx, err := types.SignTx(
types.NewTransaction(0, ethAddr, big.NewInt(123), 100000, gasPrice, []byte{}),
types.NewTransaction(0, common.Address{}, big.NewInt(123), 100000, gasPrice, []byte{}),
EVMSigner(),
ethPvtKey,
)
require.NoError(t, err)
err = jsonRPCClient.SendTransaction(context.Background(), tx)
require.NoError(t, err)
return tx
}

func TestEVMISCReceipt(t *testing.T) {
w := newWaspCLITest(t)
committee, quorum := w.ArgCommitteeConfig(0)
w.MustRun("chain", "deploy", "--chain=chain1", committee, quorum, "--node=0")
w.ActivateChainOnAllNodes("chain1", 0)
ethPvtKey, ethAddr := newEthereumAccount()
w.MustRun("chain", "deposit", ethAddr.String(), "base:100000000", "--node=0")

// send some arbitrary EVM tx
tx := sendDummyEVMTx(t, w, ethPvtKey)
out := w.MustRun("chain", "request", tx.Hash().Hex(), "--node=0")
require.Contains(t, out[0], "Request found in block")
}
Expand Down

0 comments on commit 083907b

Please sign in to comment.