Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
begmaroman committed Aug 14, 2024
1 parent e42be03 commit bc9b293
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 29 deletions.
2 changes: 2 additions & 0 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,9 @@ func buildOffchainDataInsertQuery(ods []types.OffChainData) (string, []interface
const columnsAffected = 3

// Remove duplicates from the given offchain data
fmt.Println("ods 1", ods)
ods = types.RemoveDuplicateOffChainData(ods)
fmt.Println("ods 2", ods)

args := make([]interface{}, len(ods)*columnsAffected)
values := make([]string, len(ods))
Expand Down
58 changes: 29 additions & 29 deletions db/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,26 +175,26 @@ func Test_DB_StoreUnresolvedBatchKeys(t *testing.T) {
name: "one value inserted",
bk: []types.BatchKey{{
Number: 1,
Hash: common.HexToHash("key1"),
Hash: common.BytesToHash([]byte("key1")),
}},
expectedQuery: `INSERT INTO data_node.unresolved_batches (num, hash) VALUES ($1, $2) ON CONFLICT (num, hash) DO NOTHING`,
},
{
name: "several values inserted",
bk: []types.BatchKey{{
Number: 1,
Hash: common.HexToHash("key1"),
Hash: common.BytesToHash([]byte("key1")),
}, {
Number: 2,
Hash: common.HexToHash("key2"),
Hash: common.BytesToHash([]byte("key2")),
}},
expectedQuery: `INSERT INTO data_node.unresolved_batches (num, hash) VALUES ($1, $2),($3, $4) ON CONFLICT (num, hash) DO NOTHING`,
},
{
name: "error returned",
bk: []types.BatchKey{{
Number: 1,
Hash: common.HexToHash("key1"),
Hash: common.BytesToHash([]byte("key1")),
}},
expectedQuery: `INSERT INTO data_node.unresolved_batches (num, hash) VALUES ($1, $2) ON CONFLICT (num, hash) DO NOTHING`,
returnErr: errors.New("test error"),
Expand Down Expand Up @@ -262,14 +262,14 @@ func Test_DB_GetUnresolvedBatchKeys(t *testing.T) {
name: "successfully selected data",
bks: []types.BatchKey{{
Number: 1,
Hash: common.HexToHash("key1"),
Hash: common.BytesToHash([]byte("key1")),
}},
},
{
name: "error returned",
bks: []types.BatchKey{{
Number: 1,
Hash: common.HexToHash("key1"),
Hash: common.BytesToHash([]byte("key1")),
}},
returnErr: errors.New("test error"),
},
Expand Down Expand Up @@ -332,26 +332,26 @@ func Test_DB_DeleteUnresolvedBatchKeys(t *testing.T) {
name: "value deleted",
bks: []types.BatchKey{{
Number: 1,
Hash: common.HexToHash("key1"),
Hash: common.BytesToHash([]byte("key1")),
}},
expectedQuery: `DELETE FROM data_node.unresolved_batches WHERE (num, hash) IN (($1, $2))`,
},
{
name: "multiple values deleted",
bks: []types.BatchKey{{
Number: 1,
Hash: common.HexToHash("key1"),
Hash: common.BytesToHash([]byte("key1")),
}, {
Number: 2,
Hash: common.HexToHash("key2"),
Hash: common.BytesToHash([]byte("key2")),
}},
expectedQuery: `DELETE FROM data_node.unresolved_batches WHERE (num, hash) IN (($1, $2),($3, $4))`,
},
{
name: "error returned",
bks: []types.BatchKey{{
Number: 1,
Hash: common.HexToHash("key1"),
Hash: common.BytesToHash([]byte("key1")),
}},
expectedQuery: `DELETE FROM data_node.unresolved_batches WHERE (num, hash) IN (($1, $2))`,
returnErr: errors.New("test error"),
Expand Down Expand Up @@ -416,26 +416,26 @@ func Test_DB_StoreOffChainData(t *testing.T) {
{
name: "one value inserted",
ods: []types.OffChainData{{
Key: common.HexToHash("key1"),
Key: common.BytesToHash([]byte("key1")),
Value: []byte("value1"),
}},
expectedQuery: `INSERT INTO data_node.offchain_data (key, value, batch_num) VALUES ($1, $2, $3) ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value, batch_num = EXCLUDED.batch_num`,
},
{
name: "several values inserted",
ods: []types.OffChainData{{
Key: common.HexToHash("key1"),
Key: common.BytesToHash([]byte("key1")),
Value: []byte("value1"),
}, {
Key: common.HexToHash("key2"),
Key: common.BytesToHash([]byte("key2")),
Value: []byte("value2"),
}},
expectedQuery: `INSERT INTO data_node.offchain_data (key, value, batch_num) VALUES ($1, $2, $3),($4, $5, $6) ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value, batch_num = EXCLUDED.batch_num`,
},
{
name: "error returned",
ods: []types.OffChainData{{
Key: common.HexToHash("key1"),
Key: common.BytesToHash([]byte("key1")),
Value: []byte("value1"),
}},
expectedQuery: `INSERT INTO data_node.offchain_data (key, value, batch_num) VALUES ($1, $2, $3) ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value, batch_num = EXCLUDED.batch_num`,
Expand Down Expand Up @@ -499,21 +499,21 @@ func Test_DB_GetOffChainData(t *testing.T) {
{
name: "successfully selected value",
od: []types.OffChainData{{
Key: common.HexToHash("key1"),
Key: common.BytesToHash([]byte("key1")),
Value: []byte("value1"),
BatchNum: 1,
}},
key: common.BytesToHash([]byte("key1")),
expected: &types.OffChainData{
Key: common.HexToHash("key1"),
Key: common.BytesToHash([]byte("key1")),
Value: []byte("value1"),
BatchNum: 1,
},
},
{
name: "error returned",
od: []types.OffChainData{{
Key: common.HexToHash("key1"),
Key: common.BytesToHash([]byte("key1")),
Value: []byte("value1"),
}},
key: common.BytesToHash([]byte("key1")),
Expand All @@ -522,7 +522,7 @@ func Test_DB_GetOffChainData(t *testing.T) {
{
name: "no rows",
od: []types.OffChainData{{
Key: common.HexToHash("key1"),
Key: common.BytesToHash([]byte("key1")),
Value: []byte("value1"),
}},
key: common.BytesToHash([]byte("undefined")),
Expand Down Expand Up @@ -587,7 +587,7 @@ func Test_DB_ListOffChainData(t *testing.T) {
{
name: "successfully selected one value",
od: []types.OffChainData{{
Key: common.HexToHash("key1"),
Key: common.BytesToHash([]byte("key1")),
Value: []byte("value1"),
}},
keys: []common.Hash{
Expand All @@ -605,11 +605,11 @@ func Test_DB_ListOffChainData(t *testing.T) {
{
name: "successfully selected two values",
od: []types.OffChainData{{
Key: common.HexToHash("key1"),
Key: common.BytesToHash([]byte("key1")),
Value: []byte("value1"),
BatchNum: 1,
}, {
Key: common.HexToHash("key2"),
Key: common.BytesToHash([]byte("key2")),
Value: []byte("value2"),
BatchNum: 2,
}},
Expand All @@ -634,7 +634,7 @@ func Test_DB_ListOffChainData(t *testing.T) {
{
name: "error returned",
od: []types.OffChainData{{
Key: common.HexToHash("key1"),
Key: common.BytesToHash([]byte("key1")),
Value: []byte("value1"),
}},
keys: []common.Hash{
Expand All @@ -646,7 +646,7 @@ func Test_DB_ListOffChainData(t *testing.T) {
{
name: "no rows",
od: []types.OffChainData{{
Key: common.HexToHash("key1"),
Key: common.BytesToHash([]byte("key1")),
Value: []byte("value1"),
}},
keys: []common.Hash{
Expand Down Expand Up @@ -722,10 +722,10 @@ func Test_DB_CountOffchainData(t *testing.T) {
{
name: "two values found",
od: []types.OffChainData{{
Key: common.HexToHash("key1"),
Key: common.BytesToHash([]byte("key1")),
Value: []byte("value1"),
}, {
Key: common.HexToHash("key1"),
Key: common.BytesToHash([]byte("key1")),
Value: []byte("value2"),
}},
count: 2,
Expand All @@ -737,7 +737,7 @@ func Test_DB_CountOffchainData(t *testing.T) {
{
name: "error returned",
od: []types.OffChainData{{
Key: common.HexToHash("key1"),
Key: common.BytesToHash([]byte("key1")),
Value: []byte("value1"),
}},
returnErr: errors.New("test error"),
Expand Down Expand Up @@ -797,11 +797,11 @@ func Test_DB_DetectOffchainDataGaps(t *testing.T) {
{
name: "one gap found",
seed: []types.OffChainData{{
Key: common.HexToHash("key1"),
Key: common.BytesToHash([]byte("key1")),
Value: []byte("value1"),
BatchNum: 1,
}, {
Key: common.HexToHash("key2"),
Key: common.BytesToHash([]byte("key2")),
Value: []byte("value2"),
BatchNum: 2,
}, {
Expand All @@ -816,7 +816,7 @@ func Test_DB_DetectOffchainDataGaps(t *testing.T) {
{
name: "error returned",
seed: []types.OffChainData{{
Key: common.HexToHash("key1"),
Key: common.BytesToHash([]byte("key1")),
Value: []byte("value1"),
}},
returnErr: errors.New("test error"),
Expand Down

0 comments on commit bc9b293

Please sign in to comment.