Files
atomic-swap/protocol/xmrtaker/net_test.go
2023-04-05 20:16:41 -05:00

39 lines
933 B
Go

// Copyright 2023 Athanor Labs (ON)
// SPDX-License-Identifier: LGPL-3.0-only
package xmrtaker
import (
"path"
"testing"
"github.com/cockroachdb/apd/v3"
"github.com/stretchr/testify/require"
"github.com/athanorlabs/atomic-swap/coins"
"github.com/athanorlabs/atomic-swap/common/types"
)
func newTestXMRTaker(t *testing.T) *Instance {
b := newBackend(t)
cfg := &Config{
Backend: b,
DataDir: path.Join(t.TempDir(), "xmrtaker"),
}
xmrtaker, err := NewInstance(cfg)
require.NoError(t, err)
return xmrtaker
}
func TestXMRTaker_InitiateProtocol(t *testing.T) {
a := newTestXMRTaker(t)
zero := new(apd.Decimal)
one := apd.New(1, 0)
offer := types.NewOffer(coins.ProvidesETH, zero, zero, coins.ToExchangeRate(one), types.EthAssetETH)
providesAmount := apd.New(333, -2) // 3.33
s, err := a.InitiateProtocol(testPeerID, providesAmount, offer)
require.NoError(t, err)
require.Equal(t, a.swapStates[offer.ID], s)
}