Skip to content

Commit

Permalink
db2/database: add tests + clean
Browse files Browse the repository at this point in the history
some cleanning
  • Loading branch information
Tangui-Bitfly committed Nov 13, 2024
1 parent 1d41136 commit 415c23c
Show file tree
Hide file tree
Showing 15 changed files with 331 additions and 282 deletions.
12 changes: 6 additions & 6 deletions backend/pkg/commons/db2/data/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func (store Store) BlockERC20TransfersToItems(chainID string, transfers []Transf
return nil, err
}
key := keyERC20(chainID, transfer.Indexed.ParentHash, transfer.LogIndex)
item := []database.Item{{Family: DEFAULT_FAMILY, Column: key}}
items[key] = []database.Item{{Family: DEFAULT_FAMILY, Column: DATA_COLUMN, Data: b}}
item := []database.Item{{Family: defaultFamily, Column: key}}
items[key] = []database.Item{{Family: defaultFamily, Column: dataColumn, Data: b}}

items[keyERC20Time(chainID, transfer.Indexed, transfer.Indexed.From, transfer.TxIndex, transfer.LogIndex)] = item
items[keyERC20Time(chainID, transfer.Indexed, transfer.Indexed.To, transfer.TxIndex, transfer.LogIndex)] = item
Expand Down Expand Up @@ -74,8 +74,8 @@ func (store Store) BlockTransactionsToItems(chainID string, transactions []*type
return nil, err
}
key := keyTx(chainID, transaction.GetHash())
item := []database.Item{{Family: DEFAULT_FAMILY, Column: key}}
items[key] = []database.Item{{Family: DEFAULT_FAMILY, Column: DATA_COLUMN, Data: b}}
item := []database.Item{{Family: defaultFamily, Column: key}}
items[key] = []database.Item{{Family: defaultFamily, Column: dataColumn, Data: b}}
items[keyTxSent(chainID, transaction, i)] = item
items[keyTxReceived(chainID, transaction, i)] = item

Expand Down Expand Up @@ -171,7 +171,7 @@ func (store Store) getBy(unMarshal unMarshalInteraction, chainIDs []string, addr
txKeys := make(map[string]string)
for _, row := range indexRows {
for key := range row.Values {
txKey := strings.TrimPrefix(key, fmt.Sprintf("%s:", DEFAULT_FAMILY))
txKey := strings.TrimPrefix(key, fmt.Sprintf("%s:", defaultFamily))
txKeys[txKey] = row.Key
}
}
Expand All @@ -180,7 +180,7 @@ func (store Store) getBy(unMarshal unMarshalInteraction, chainIDs []string, addr
return nil, err
}
for _, row := range txRows {
interaction, err := unMarshal(row.Values[fmt.Sprintf("%s:%s", DEFAULT_FAMILY, DATA_COLUMN)])
interaction, err := unMarshal(row.Values[fmt.Sprintf("%s:%s", defaultFamily, dataColumn)])
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions backend/pkg/commons/db2/data/data_external_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func dbFromEnv(t *testing.T, table string) database.Database {
if err != nil {
t.Fatal(err)
}
return database.Wrap(db, table, "")
return database.Wrap(db, table)
}
if remote != "" {
return database.NewRemoteClient(remote)
Expand All @@ -44,7 +44,7 @@ func dbFromEnv(t *testing.T, table string) database.Database {
}

func TestStoreExternal(t *testing.T) {
db := dbFromEnv(t, data.DataTable)
db := dbFromEnv(t, data.Table)
store := data.NewStore(db)

/*
Expand Down
2 changes: 1 addition & 1 deletion backend/pkg/commons/db2/data/data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestStore(t *testing.T) {
t.Fatal(err)
}
store := Store{
db: database.Wrap(s, DataTable, ""),
db: database.Wrap(s, Table),
}

tests := []struct {
Expand Down
2 changes: 1 addition & 1 deletion backend/pkg/commons/db2/data/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func newChainFilterTransfer() *chainFilterTransfer {
}
}

func (c *chainFilterTransfer) addByMethod(method string) error {
func (c *chainFilterTransfer) addByMethod(string) error {
return fmt.Errorf("cannot filter transfer by method")
}

Expand Down
16 changes: 8 additions & 8 deletions backend/pkg/commons/db2/data/tables.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package data

const (
DEFAULT_FAMILY = "f"
DATA_COLUMN = "d"

DataTable = "data"
)
const Table = "data"

var Schema = map[string][]string{
DataTable: {
DEFAULT_FAMILY,
Table: {
defaultFamily,
},
}

const (
defaultFamily = "f"
dataColumn = "d"
)
Loading

0 comments on commit 415c23c

Please sign in to comment.