Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaiba committed Feb 19, 2025
1 parent 3e9e64a commit a34fbae
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 23 deletions.
3 changes: 2 additions & 1 deletion app/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import (
"crypto/tls"
"errors"
"fmt"
"golang.org/x/sync/errgroup"
"io"
"os"
"path/filepath"
"runtime"
"slices"

"golang.org/x/sync/errgroup"

"github.com/kwilteam/kwil-db/app/key"
"github.com/kwilteam/kwil-db/config"
"github.com/kwilteam/kwil-db/core/crypto"
Expand Down
2 changes: 1 addition & 1 deletion node/exts/erc20reward/meta_extension.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// package meta implements a meta extension that manages all rewards on a Kwil network.
// package erc20reward implements a meta extension that manages all rewards on a Kwil network.
// It is used to create other extensions with which users can distribute erc20 tokens
// to users.
// It works by exposing an action to the DB owner which allows creation of new extensions
Expand Down
13 changes: 1 addition & 12 deletions node/exts/erc20reward/meta_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,7 @@ func rowToEpoch(r *common.Row) (*Epoch, error) {
confirmed := r.Values[7].(bool)

// NOTE: empty value is [[]]
// NOTE: should not use append, we could accidently skip some 'nil' element and messup the index
// But we can be sure values[7]-values[10] will all be empty if any, from the SQL;
// values[7]-values[10] will all be empty if any, from the SQL;
var voters []ethcommon.Address
if r.Values[8] != nil {
rawVoters := r.Values[8].([][]byte)
Expand Down Expand Up @@ -619,16 +618,6 @@ func voteEpoch(ctx context.Context, app *common.App, epochID *types.UUID,
}, nil)
}

// removeEpochVotes removes all votes associated with an epoch.
func removeEpochVotes(ctx context.Context, app *common.App, epochID *types.UUID) error {
return app.Engine.ExecuteWithoutEngineCtx(ctx, app.DB, `
{kwil_erc20_meta}DELETE FROM epoch_votes
WHERE epoch_id = $epoch_id;
`, map[string]any{
"epoch_id": epochID,
}, nil)
}

// getWalletEpochs returns all confirmed epochs that the given wallet has reward in.
// If pending=true, return all finalized epochs(no necessary confirmed).
func getWalletEpochs(ctx context.Context, app *common.App, instanceID *types.UUID,
Expand Down
7 changes: 5 additions & 2 deletions node/exts/erc20reward/meta_sql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package erc20reward

import (
"context"
"math/big"
"testing"

ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
"testing"

"github.com/kwilteam/kwil-db/common"
"github.com/kwilteam/kwil-db/core/log"
Expand Down Expand Up @@ -134,8 +136,9 @@ func TestCreateNewRewardInstance(t *testing.T) {
require.Equal(t, int64(18), rewards[0].syncedRewardData.Erc20Decimals)

root := []byte{0x03, 0x04}
amt, _ := erc20ValueFromBigInt(big.NewInt(100))
// finalize the epoch
err = finalizeEpoch(ctx, app, pending.ID, 20, []byte{0x01, 0x02}, root)
err = finalizeEpoch(ctx, app, pending.ID, 20, []byte{0x01, 0x02}, root, amt)
require.NoError(t, err)

// confirm the epoch
Expand Down
1 change: 1 addition & 0 deletions node/exts/erc20reward/named_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package erc20reward
import (
"context"
"errors"

"github.com/kwilteam/kwil-db/common"
"github.com/kwilteam/kwil-db/core/types"
"github.com/kwilteam/kwil-db/extensions/precompiles"
Expand Down
9 changes: 5 additions & 4 deletions node/exts/erc20reward/reward/mtree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package reward

import (
"encoding/hex"
"math/big"
"strings"
"testing"

Expand Down Expand Up @@ -48,7 +49,7 @@ func TestMerkleTree(t *testing.T) {
mtRoot, mtProof, mtLeaf, bh, amt, err := GetMTreeProof(mt, user2)
require.NoError(t, err)
require.Equal(t, expectRoot, hex.EncodeToString(mtRoot))
require.Equal(t, "200", amt)
require.Equal(t, big.NewInt(200), amt)
require.EqualValues(t, kwilBlockHashBytes, bh)
require.Len(t, mtProof, 2)
assert.Equal(t, "0x644f999664d65d1d2a3feefade54d643dc2b9696971e9070c36f0ec788e55f5b", hexutil.Encode(mtProof[0]))
Expand All @@ -66,7 +67,7 @@ func TestMerkleTree(t *testing.T) {
mtRoot, mtProof, mtLeaf, bh, amt, err := GetMTreeProof(mt, user2)
require.NoError(t, err)
require.Equal(t, expectRoot, hex.EncodeToString(mtRoot))
require.Equal(t, "200", amt)
require.Equal(t, big.NewInt(200), amt)
require.EqualValues(t, kwilBlockHashBytes, bh)
require.Len(t, mtProof, 2)
assert.Equal(t, "0x644f999664d65d1d2a3feefade54d643dc2b9696971e9070c36f0ec788e55f5b", hexutil.Encode(mtProof[0]))
Expand All @@ -84,7 +85,7 @@ func TestMerkleTree(t *testing.T) {
mtRoot, mtProof, mtLeaf, bh, amt, err := GetMTreeProof(mt, user2)
require.NoError(t, err)
require.Equal(t, expectRoot, hex.EncodeToString(mtRoot))
require.Equal(t, "200", amt)
require.Equal(t, big.NewInt(200), amt)
require.EqualValues(t, kwilBlockHashBytes, bh)
require.Len(t, mtProof, 3)
assert.Equal(t, "0x644f999664d65d1d2a3feefade54d643dc2b9696971e9070c36f0ec788e55f5b", hexutil.Encode(mtProof[0]))
Expand All @@ -101,7 +102,7 @@ func TestMerkleTree(t *testing.T) {
mtRoot, mtProof, mtLeaf, bh, amt, err := GetMTreeProof(mt, user1)
require.NoError(t, err)
require.Equal(t, root, mtRoot)
require.Equal(t, "100", amt)
require.Equal(t, big.NewInt(100), amt)
require.EqualValues(t, kwilBlockHashBytes, bh)
require.Len(t, mtProof, 0) // no proofs
assert.Equal(t, root, mtLeaf) // the leaf is the root
Expand Down
5 changes: 2 additions & 3 deletions node/services/erc20signersvc/kwil.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,8 @@ type erc20ExtAPI interface {
}

type erc20rwExtApi struct {
clt *client.Client
namespace string
instanceID string
clt *client.Client
namespace string
}

var _ erc20ExtAPI = (*erc20rwExtApi)(nil)
Expand Down

0 comments on commit a34fbae

Please sign in to comment.