storj/satellite/payments/coinpayments/transactions_test.go
Egon Elbre 1137620baf satellite/satellitedb: move tests to their domains
Testing interfaces is slightly clearer when it's in the package needing
the database rather than each individual implementation.

Change-Id: I10334c214a205f7e510b939b4359a2214c4e060a
2021-02-19 17:29:15 +02:00

60 lines
1.7 KiB
Go

// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
package coinpayments_test
import (
"math/big"
"testing"
"github.com/stretchr/testify/assert"
"storj.io/common/testcontext"
"storj.io/storj/satellite"
"storj.io/storj/satellite/payments/coinpayments"
"storj.io/storj/satellite/satellitedb/satellitedbtest"
)
func TestListInfos(t *testing.T) {
// This test is deliberately skipped as it requires credentials to coinpayments.net
t.SkipNow()
ctx := testcontext.New(t)
defer ctx.Cleanup()
payments := coinpayments.NewClient(coinpayments.Credentials{
PublicKey: "ask-littleskunk-on-keybase",
PrivateKey: "ask-littleskunk-on-keybase",
}).Transactions()
// verify that bad ids fail
infos, err := payments.ListInfos(ctx, coinpayments.TransactionIDList{"an_unlikely_id"})
assert.Error(t, err)
assert.Len(t, infos, 0)
// verify that ListInfos can handle more than 25 good ids
ids := coinpayments.TransactionIDList{}
for x := 0; x < 27; x++ {
tx, err := payments.Create(ctx,
&coinpayments.CreateTX{
Amount: *big.NewFloat(100),
CurrencyIn: coinpayments.CurrencySTORJ,
CurrencyOut: coinpayments.CurrencySTORJ,
BuyerEmail: "test@test.com",
},
)
ids = append(ids, tx.ID)
assert.NoError(t, err)
}
infos, err = payments.ListInfos(ctx, ids)
assert.NoError(t, err)
assert.Len(t, infos, 27)
}
func TestUpdateSameAppliesDoesNotExplode(t *testing.T) {
satellitedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db satellite.DB) {
tdb := db.StripeCoinPayments().Transactions()
assert.NoError(t, tdb.Update(ctx, nil, coinpayments.TransactionIDList{"blah", "blah"}))
assert.NoError(t, tdb.Update(ctx, nil, coinpayments.TransactionIDList{"blah", "blah"}))
})
}