storj/satellite/snopayout/payout_test.go
Qweder93 8182fdad0b storagenode: heldamount renamed to payouts, renamed some methods and structs to more meaningful names. grouped estimated payout with pathouts
satellite: heldamount renamed to SNOpayouts.

Change-Id: I244b4d2454e0621f4b8e22d3c0d3e602c0bbcb02
2020-09-16 14:57:35 +00:00

242 lines
8.6 KiB
Go

// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
package snopayout_test
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"storj.io/common/storj"
"storj.io/common/testcontext"
"storj.io/common/testrand"
"storj.io/storj/satellite"
"storj.io/storj/satellite/satellitedb/satellitedbtest"
"storj.io/storj/satellite/snopayout"
)
func TestPayoutDB(t *testing.T) {
satellitedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db satellite.DB) {
snoPayout := db.SnoPayout()
NodeID := storj.NodeID{}
period := "2020-01"
paystub := snopayout.PayStub{
Period: "2020-01",
NodeID: NodeID,
Created: time.Now().UTC(),
Codes: "1",
UsageAtRest: 1,
UsageGet: 2,
UsagePut: 3,
UsageGetRepair: 4,
UsagePutRepair: 5,
UsageGetAudit: 6,
CompAtRest: 7,
CompGet: 8,
CompPut: 9,
CompGetRepair: 10,
CompPutRepair: 11,
CompGetAudit: 12,
SurgePercent: 13,
Held: 14,
Owed: 15,
Disposed: 16,
Paid: 17,
}
paystub2 := snopayout.PayStub{
Period: "2020-02",
NodeID: NodeID,
Created: time.Now().UTC(),
Codes: "2",
UsageAtRest: 4,
UsageGet: 5,
UsagePut: 6,
UsageGetRepair: 7,
UsagePutRepair: 8,
UsageGetAudit: 9,
CompAtRest: 10,
CompGet: 11,
CompPut: 12,
CompGetRepair: 13,
CompPutRepair: 14,
CompGetAudit: 15,
SurgePercent: 16,
Held: 17,
Owed: 18,
Disposed: 19,
Paid: 20,
}
paystub3 := snopayout.PayStub{
Period: "2020-03",
NodeID: NodeID,
Created: time.Now().UTC(),
Codes: "33",
UsageAtRest: 10,
UsageGet: 11,
UsagePut: 12,
UsageGetRepair: 13,
UsagePutRepair: 14,
UsageGetAudit: 15,
CompAtRest: 16,
CompGet: 17,
CompPut: 18,
CompGetRepair: 19,
CompPutRepair: 20,
CompGetAudit: 21,
SurgePercent: 22,
Held: 23,
Owed: 24,
Disposed: 25,
Paid: 26,
}
t.Run("Test StorePayStub", func(t *testing.T) {
err := snoPayout.CreatePaystub(ctx, paystub)
assert.NoError(t, err)
err = snoPayout.CreatePaystub(ctx, paystub2)
assert.NoError(t, err)
err = snoPayout.CreatePaystub(ctx, paystub3)
assert.NoError(t, err)
})
t.Run("Test GetPayStub", func(t *testing.T) {
stub, err := snoPayout.GetPaystub(ctx, NodeID, period)
assert.NoError(t, err)
assert.Equal(t, stub.Period, paystub.Period)
assert.Equal(t, stub.Codes, paystub.Codes)
assert.Equal(t, stub.CompAtRest, paystub.CompAtRest)
assert.Equal(t, stub.CompGet, paystub.CompGet)
assert.Equal(t, stub.CompGetAudit, paystub.CompGetAudit)
assert.Equal(t, stub.CompGetRepair, paystub.CompGetRepair)
assert.Equal(t, stub.CompPut, paystub.CompPut)
assert.Equal(t, stub.CompPutRepair, paystub.CompPutRepair)
assert.Equal(t, stub.Disposed, paystub.Disposed)
assert.Equal(t, stub.Held, paystub.Held)
assert.Equal(t, stub.Owed, paystub.Owed)
assert.Equal(t, stub.Paid, paystub.Paid)
assert.Equal(t, stub.NodeID, paystub.NodeID)
assert.Equal(t, stub.SurgePercent, paystub.SurgePercent)
assert.Equal(t, stub.UsageAtRest, paystub.UsageAtRest)
assert.Equal(t, stub.UsageGet, paystub.UsageGet)
assert.Equal(t, stub.UsageGetAudit, paystub.UsageGetAudit)
assert.Equal(t, stub.UsageGetRepair, paystub.UsageGetRepair)
assert.Equal(t, stub.UsagePut, paystub.UsagePut)
assert.Equal(t, stub.UsagePutRepair, paystub.UsagePutRepair)
stub, err = snoPayout.GetPaystub(ctx, NodeID, "")
assert.Error(t, err)
stub, err = snoPayout.GetPaystub(ctx, storj.NodeID{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, period)
assert.Error(t, err)
})
t.Run("Test GetAllPaystubs", func(t *testing.T) {
stubs, err := snoPayout.GetAllPaystubs(ctx, NodeID)
assert.NoError(t, err)
for i := 0; i < len(stubs); i++ {
if stubs[i].Period == "2020-01" {
assert.Equal(t, stubs[i].Period, paystub.Period)
assert.Equal(t, stubs[i].Codes, paystub.Codes)
assert.Equal(t, stubs[i].CompAtRest, paystub.CompAtRest)
assert.Equal(t, stubs[i].CompGet, paystub.CompGet)
assert.Equal(t, stubs[i].CompGetAudit, paystub.CompGetAudit)
assert.Equal(t, stubs[i].CompGetRepair, paystub.CompGetRepair)
assert.Equal(t, stubs[i].CompPut, paystub.CompPut)
assert.Equal(t, stubs[i].CompPutRepair, paystub.CompPutRepair)
assert.Equal(t, stubs[i].Disposed, paystub.Disposed)
assert.Equal(t, stubs[i].Held, paystub.Held)
assert.Equal(t, stubs[i].Owed, paystub.Owed)
assert.Equal(t, stubs[i].Paid, paystub.Paid)
assert.Equal(t, stubs[i].NodeID, paystub.NodeID)
assert.Equal(t, stubs[i].SurgePercent, paystub.SurgePercent)
assert.Equal(t, stubs[i].UsageAtRest, paystub.UsageAtRest)
assert.Equal(t, stubs[i].UsageGet, paystub.UsageGet)
assert.Equal(t, stubs[i].UsageGetAudit, paystub.UsageGetAudit)
assert.Equal(t, stubs[i].UsageGetRepair, paystub.UsageGetRepair)
assert.Equal(t, stubs[i].UsagePut, paystub.UsagePut)
assert.Equal(t, stubs[i].UsagePutRepair, paystub.UsagePutRepair)
}
if stubs[i].Period == "2020-02" {
assert.Equal(t, stubs[i].Period, paystub2.Period)
assert.Equal(t, stubs[i].Codes, paystub2.Codes)
assert.Equal(t, stubs[i].CompAtRest, paystub2.CompAtRest)
assert.Equal(t, stubs[i].CompGet, paystub2.CompGet)
assert.Equal(t, stubs[i].CompGetAudit, paystub2.CompGetAudit)
assert.Equal(t, stubs[i].CompGetRepair, paystub2.CompGetRepair)
assert.Equal(t, stubs[i].CompPut, paystub2.CompPut)
assert.Equal(t, stubs[i].CompPutRepair, paystub2.CompPutRepair)
assert.Equal(t, stubs[i].Disposed, paystub2.Disposed)
assert.Equal(t, stubs[i].Held, paystub2.Held)
assert.Equal(t, stubs[i].Owed, paystub2.Owed)
assert.Equal(t, stubs[i].Paid, paystub2.Paid)
assert.Equal(t, stubs[i].NodeID, paystub2.NodeID)
assert.Equal(t, stubs[i].SurgePercent, paystub2.SurgePercent)
assert.Equal(t, stubs[i].UsageAtRest, paystub2.UsageAtRest)
assert.Equal(t, stubs[i].UsageGet, paystub2.UsageGet)
assert.Equal(t, stubs[i].UsageGetAudit, paystub2.UsageGetAudit)
assert.Equal(t, stubs[i].UsageGetRepair, paystub2.UsageGetRepair)
assert.Equal(t, stubs[i].UsagePut, paystub2.UsagePut)
assert.Equal(t, stubs[i].UsagePutRepair, paystub2.UsagePutRepair)
}
if stubs[i].Period == "2020-03" {
assert.Equal(t, stubs[i].Period, paystub3.Period)
assert.Equal(t, stubs[i].Codes, paystub3.Codes)
assert.Equal(t, stubs[i].CompAtRest, paystub3.CompAtRest)
assert.Equal(t, stubs[i].CompGet, paystub3.CompGet)
assert.Equal(t, stubs[i].CompGetAudit, paystub3.CompGetAudit)
assert.Equal(t, stubs[i].CompGetRepair, paystub3.CompGetRepair)
assert.Equal(t, stubs[i].CompPut, paystub3.CompPut)
assert.Equal(t, stubs[i].CompPutRepair, paystub3.CompPutRepair)
assert.Equal(t, stubs[i].Disposed, paystub3.Disposed)
assert.Equal(t, stubs[i].Held, paystub3.Held)
assert.Equal(t, stubs[i].Owed, paystub3.Owed)
assert.Equal(t, stubs[i].Paid, paystub3.Paid)
assert.Equal(t, stubs[i].NodeID, paystub3.NodeID)
assert.Equal(t, stubs[i].SurgePercent, paystub3.SurgePercent)
assert.Equal(t, stubs[i].UsageAtRest, paystub3.UsageAtRest)
assert.Equal(t, stubs[i].UsageGet, paystub3.UsageGet)
assert.Equal(t, stubs[i].UsageGetAudit, paystub3.UsageGetAudit)
assert.Equal(t, stubs[i].UsageGetRepair, paystub3.UsageGetRepair)
assert.Equal(t, stubs[i].UsagePut, paystub3.UsagePut)
assert.Equal(t, stubs[i].UsagePutRepair, paystub3.UsagePutRepair)
}
}
})
payment := snopayout.StoragenodePayment{
ID: 1,
Created: time.Now().UTC(),
NodeID: NodeID,
Period: "2020-01",
Amount: 123,
Receipt: "receipt",
Notes: "notes",
}
t.Run("Test StorePayment", func(t *testing.T) {
err := snoPayout.CreatePayment(ctx, payment)
assert.NoError(t, err)
})
t.Run("Test GetPayment", func(t *testing.T) {
paym, err := snoPayout.GetPayment(ctx, NodeID, period)
assert.NoError(t, err)
assert.Equal(t, paym.NodeID, payment.NodeID)
assert.Equal(t, paym.Period, payment.Period)
assert.Equal(t, paym.Amount, payment.Amount)
assert.Equal(t, paym.Notes, payment.Notes)
assert.Equal(t, paym.Receipt, payment.Receipt)
paym, err = snoPayout.GetPayment(ctx, NodeID, "")
assert.Error(t, err)
paym, err = snoPayout.GetPayment(ctx, testrand.NodeID(), period)
assert.Error(t, err)
})
})
}