mirror of
https://github.com/eosswedenorg/thalos
synced 2026-12-03 09:06:45 +01:00
ship: add table delta whitelist filtering
This commit is contained in:
parent
d985133d9a
commit
90a8de15fe
8 changed files with 248 additions and 12 deletions
79
internal/server/ship_processor_test.go
Normal file
79
internal/server/ship_processor_test.go
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/eosswedenorg/thalos/api/message"
|
||||
"github.com/eosswedenorg/thalos/internal/types"
|
||||
"github.com/shufflingpixels/antelope-go/chain"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestShipProcessor_ShouldProcessTableDeltaName(t *testing.T) {
|
||||
processor := &ShipProcessor{}
|
||||
|
||||
require.True(t, processor.shouldProcessTableDeltaName("contract_row"))
|
||||
require.True(t, processor.shouldProcessTableDeltaName("resource_limits"))
|
||||
|
||||
processor.SetTableDeltaWhitelist(*types.NewBlacklist(map[string][]string{
|
||||
"eosio.token": {"accounts"},
|
||||
}))
|
||||
|
||||
require.True(t, processor.shouldProcessTableDeltaName("contract_row"))
|
||||
require.False(t, processor.shouldProcessTableDeltaName("resource_limits"))
|
||||
}
|
||||
|
||||
func TestShipProcessor_FilterWhitelistedContractRows(t *testing.T) {
|
||||
processor := &ShipProcessor{}
|
||||
processor.SetTableDeltaWhitelist(*types.NewBlacklist(map[string][]string{
|
||||
"eosio.token": {"accounts"},
|
||||
"eosio": {"*"},
|
||||
}))
|
||||
|
||||
rows := []message.TableDeltaRow{
|
||||
{Data: map[string]any{"code": "eosio.token", "table": "accounts"}},
|
||||
{Data: map[string]any{"code": "eosio.token", "table": "stat"}},
|
||||
{Data: map[string]any{"code": "eosio", "table": "users"}},
|
||||
{Data: map[string]any{"scope": "missing-code"}},
|
||||
{Data: map[string]any{"code": 42, "table": "accounts"}},
|
||||
{Data: map[string]any{"code": "eosio.token", "table": 1}},
|
||||
{Data: nil},
|
||||
}
|
||||
|
||||
actual := processor.filterWhitelistedContractRows(rows)
|
||||
|
||||
require.Len(t, actual, 2)
|
||||
require.Equal(t, "eosio.token", actual[0].Data["code"])
|
||||
require.Equal(t, "accounts", actual[0].Data["table"])
|
||||
require.Equal(t, "eosio", actual[1].Data["code"])
|
||||
}
|
||||
|
||||
func TestShipProcessor_FilterWhitelistedContractRows_StringerCode(t *testing.T) {
|
||||
processor := &ShipProcessor{}
|
||||
processor.SetTableDeltaWhitelist(*types.NewBlacklist(map[string][]string{
|
||||
"eosio.token": {"accounts"},
|
||||
}))
|
||||
|
||||
rows := []message.TableDeltaRow{
|
||||
{Data: map[string]any{"code": chain.N("eosio.token"), "table": chain.N("accounts")}},
|
||||
{Data: map[string]any{"code": chain.N("eosio.token"), "table": chain.N("stat")}},
|
||||
}
|
||||
|
||||
actual := processor.filterWhitelistedContractRows(rows)
|
||||
|
||||
require.Len(t, actual, 1)
|
||||
require.Equal(t, chain.N("eosio.token"), actual[0].Data["code"])
|
||||
}
|
||||
|
||||
func TestShipProcessor_FilterWhitelistedContractRows_NoWhitelist(t *testing.T) {
|
||||
processor := &ShipProcessor{}
|
||||
|
||||
rows := []message.TableDeltaRow{
|
||||
{Data: map[string]any{"code": "eosio.token", "table": "accounts"}},
|
||||
{Data: map[string]any{"scope": "missing-code"}},
|
||||
}
|
||||
|
||||
actual := processor.filterWhitelistedContractRows(rows)
|
||||
|
||||
require.Equal(t, rows, actual)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue