2024-02-20 15:49:39 +00:00
|
|
|
package storenodes
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2024-08-16 18:24:21 +00:00
|
|
|
"github.com/multiformats/go-multiaddr"
|
2024-02-20 15:49:39 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
"github.com/status-im/status-go/eth-node/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
communityID1 = types.HexBytes("community001")
|
|
|
|
communityID2 = types.HexBytes("community002")
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSyncSave(t *testing.T) {
|
|
|
|
db, close := setupTestDB(t, communityID1)
|
|
|
|
defer close()
|
2024-08-16 18:24:21 +00:00
|
|
|
|
|
|
|
maddr, err := multiaddr.NewMultiaddr("/dns4/test.net/tcp/30303/p2p/16Uiu2HAmMELCo218hncCtTvC2Dwbej3rbyHQcR8erXNnKGei7WPZ")
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
2024-02-20 15:49:39 +00:00
|
|
|
snodes := []Storenode{
|
|
|
|
{
|
|
|
|
CommunityID: communityID1,
|
|
|
|
StorenodeID: "storenode001",
|
|
|
|
Name: "My Mailserver",
|
2024-08-16 18:24:21 +00:00
|
|
|
Address: maddr,
|
2024-02-20 15:49:39 +00:00
|
|
|
Fleet: "prod",
|
|
|
|
Version: 2,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// ========
|
|
|
|
// Save
|
|
|
|
|
2024-08-16 18:24:21 +00:00
|
|
|
err = db.syncSave(communityID1, snodes, 0)
|
2024-02-20 15:49:39 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
dbNodes, err := db.getByCommunityID(communityID1)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Len(t, dbNodes, 1)
|
|
|
|
require.ElementsMatch(t, dbNodes, snodes)
|
|
|
|
|
|
|
|
// ========
|
|
|
|
// Update
|
|
|
|
|
|
|
|
updated := []Storenode{
|
|
|
|
{
|
|
|
|
CommunityID: communityID1,
|
|
|
|
StorenodeID: "storenode001",
|
|
|
|
Name: "My Mailserver 2",
|
2024-08-16 18:24:21 +00:00
|
|
|
Address: maddr,
|
2024-02-20 15:49:39 +00:00
|
|
|
Fleet: "prod",
|
|
|
|
Version: 2,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
err = db.syncSave(communityID1, updated, 0)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
dbNodes, err = db.getByCommunityID(communityID1)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Len(t, dbNodes, 1)
|
|
|
|
require.ElementsMatch(t, dbNodes, updated)
|
|
|
|
|
|
|
|
// ========
|
|
|
|
// Remove
|
|
|
|
|
|
|
|
err = db.syncSave(communityID1, []Storenode{}, 0)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
dbNodes, err = db.getByCommunityID(communityID1)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
require.Len(t, dbNodes, 0)
|
|
|
|
}
|