storj/satellite/payments/storjscan/wallets_test.go
Márton Elek 5e8266d1de satellite/{payments/storjscan,satellitedb}: Add storjscan wallet DB
Add storjscan wallets DB to the satellite. For now this DB is a one to one mapping of the users account to a storjscan wallet that can be used by the account holder to make payments on their Storj account.

relates to https://github.com/storj/storj/issues/4347

Change-Id: I6e65b15817b90ceb75641244f9bf173c3b4228a7
2022-05-24 08:42:02 +00:00

50 lines
1.5 KiB
Go

// Copyright (C) 2022 Storj Labs, Inc.
// See LICENSE for copying information.
package storjscan_test
import (
"testing"
"github.com/stretchr/testify/require"
"storj.io/common/testcontext"
"storj.io/common/testrand"
"storj.io/storj/private/blockchain"
"storj.io/storj/satellite"
"storj.io/storj/satellite/satellitedb/satellitedbtest"
)
func TestWalletsDB(t *testing.T) {
userID1 := testrand.UUID()
userID2 := testrand.UUID()
userID3 := testrand.UUID()
walletAddress1, err := blockchain.BytesToAddress(testrand.Bytes(20))
require.NoError(t, err)
walletAddress2, err := blockchain.BytesToAddress(testrand.Bytes(20))
require.NoError(t, err)
walletAddress3, err := blockchain.BytesToAddress(testrand.Bytes(20))
require.NoError(t, err)
t.Run("get wallet", func(t *testing.T) {
satellitedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db satellite.DB) {
err := db.Wallets().Add(ctx, userID1, walletAddress1)
require.NoError(t, err)
err = db.Wallets().Add(ctx, userID2, walletAddress2)
require.NoError(t, err)
err = db.Wallets().Add(ctx, userID3, walletAddress3)
require.NoError(t, err)
address1, err := db.Wallets().Get(ctx, userID1)
require.NoError(t, err)
require.Equal(t, walletAddress1, address1)
address2, err := db.Wallets().Get(ctx, userID2)
require.NoError(t, err)
require.Equal(t, walletAddress2, address2)
address3, err := db.Wallets().Get(ctx, userID3)
require.NoError(t, err)
require.Equal(t, walletAddress3, address3)
})
})
}