storj/testsuite/storjscan/chore_test.go
Yaroslav Vorobiov 7a9b2a707b satellite/payments/monetary: add USDMicro and json marshaling
Adds USDMicro currency which support fraction of a cent with decimal places
for better billing amounts accuracy.
Adds JSON marshaling and unmarshaling for monetary.Amount, so that it
can be converted to/from JSON.

Change-Id: I034eba120ed23b6ba00b2d81a4f1b9db5f9a203f
2022-08-18 18:38:01 +00:00

76 lines
2.4 KiB
Go

// Copyright (C) 2022 Storj Labs, Inc.
// See LICENSE for copying information.
package storjscan
import (
"math/big"
"testing"
"time"
"github.com/stretchr/testify/require"
"storj.io/common/testcontext"
blockchain2 "storj.io/storj/private/blockchain"
"storj.io/storj/private/testplanet"
"storj.io/storj/satellite/payments"
"storj.io/storj/satellite/payments/monetary"
"storj.io/storj/testsuite/storjscan/storjscantest"
"storj.io/storjscan/blockchain"
"storj.io/storjscan/private/testeth/testtoken"
)
func TestChore(t *testing.T) {
storjscantest.Run(t, func(t *testing.T, ctx *testcontext.Context, planet *testplanet.Planet, stack *storjscantest.Stack) {
receiver, _ := blockchain.AddressFromHex("0x27e3d303B0B70B1b17f14525b48Ae7c45D34666f")
err := stack.App.Wallets.Service.Register(ctx, "eu", map[blockchain.Address]string{
receiver: "test",
})
require.NoError(t, err)
sat := planet.Satellites[0]
sat.Core.Payments.StorjscanChore.TransactionCycle.Pause()
// claim wallet
_, err = sat.API.Payments.StorjscanClient.ClaimNewEthAddress(ctx)
require.NoError(t, err)
client := stack.Network.Dial()
defer client.Close()
accs := stack.Network.Accounts()
tk, err := testtoken.NewTestToken(blockchain.Address(stack.Token), client)
require.NoError(t, err)
opts := stack.Network.TransactOptions(ctx, accs[0], 1)
tx, err := tk.Transfer(opts, receiver, big.NewInt(10000))
require.NoError(t, err)
rcpt, err := stack.Network.WaitForTx(ctx, tx.Hash())
require.NoError(t, err)
block, err := client.BlockByNumber(ctx, rcpt.BlockNumber)
require.NoError(t, err)
blockTime := time.Unix(int64(block.Time()), 0)
sat.Core.Payments.StorjscanChore.TransactionCycle.TriggerWait()
pmnts, err := sat.API.Payments.StorjscanService.Payments(ctx, blockchain2.Address(receiver), 1, 0)
require.NoError(t, err)
require.Len(t, pmnts, 1)
expected := payments.WalletPayment{
From: blockchain2.Address(accs[0].Address),
To: blockchain2.Address(receiver),
TokenValue: monetary.AmountFromBaseUnits(10000, monetary.StorjToken),
USDValue: monetary.AmountFromBaseUnits(1000000, monetary.USDollars),
Status: payments.PaymentStatusPending,
BlockHash: blockchain2.Hash(block.Hash()),
BlockNumber: block.Number().Int64(),
Transaction: blockchain2.Hash(rcpt.TxHash),
LogIndex: 0,
Timestamp: blockTime.UTC(),
}
require.Equal(t, expected, pmnts[0])
})
}