mirror of
https://github.com/AthanorLabs/atomic-swap.git
synced 2026-01-09 14:18:03 -05:00
99 lines
2.3 KiB
Go
99 lines
2.3 KiB
Go
// Copyright 2023 The AthanorLabs/atomic-swap Authors
|
|
// SPDX-License-Identifier: LGPL-3.0-only
|
|
|
|
package protocol
|
|
|
|
import (
|
|
"context"
|
|
"path"
|
|
"testing"
|
|
|
|
"github.com/athanorlabs/atomic-swap/coins"
|
|
"github.com/athanorlabs/atomic-swap/common"
|
|
mcrypto "github.com/athanorlabs/atomic-swap/crypto/monero"
|
|
"github.com/athanorlabs/atomic-swap/monero"
|
|
|
|
logging "github.com/ipfs/go-log"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
var (
|
|
_ = logging.SetLogLevel("monero", "debug")
|
|
_ = logging.SetLogLevel("protocol", "debug")
|
|
)
|
|
|
|
func TestClaimMonero_NoTransferBack(t *testing.T) {
|
|
env := common.Development
|
|
|
|
kp, err := mcrypto.GenerateKeys()
|
|
require.NoError(t, err)
|
|
|
|
conf := &monero.WalletClientConf{
|
|
Env: env,
|
|
WalletFilePath: path.Join(t.TempDir(), "test-wallet-tcm"),
|
|
MoneroWalletRPCPath: monero.GetWalletRPCDirectory(t),
|
|
}
|
|
err = conf.Fill()
|
|
require.NoError(t, err)
|
|
|
|
moneroCli, err := monero.CreateSpendWalletFromKeys(conf, kp, 0)
|
|
require.NoError(t, err)
|
|
height, err := moneroCli.GetHeight()
|
|
require.NoError(t, err)
|
|
xmrAmt := coins.StrToDecimal("1")
|
|
pnAmt := coins.MoneroToPiconero(xmrAmt)
|
|
monero.MineMinXMRBalance(t, moneroCli, pnAmt)
|
|
|
|
err = ClaimMonero(
|
|
context.Background(),
|
|
common.Development,
|
|
[32]byte{},
|
|
moneroCli,
|
|
height,
|
|
kp,
|
|
nil, // deposit address can be nil, as noTransferBack is true
|
|
true,
|
|
)
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
func TestClaimMonero_WithTransferBack(t *testing.T) {
|
|
monero.TestBackgroundMineBlocks(t)
|
|
env := common.Development
|
|
|
|
kp, err := mcrypto.GenerateKeys()
|
|
require.NoError(t, err)
|
|
|
|
conf := &monero.WalletClientConf{
|
|
Env: env,
|
|
WalletFilePath: path.Join(t.TempDir(), "test-wallet-tcm"),
|
|
MoneroWalletRPCPath: monero.GetWalletRPCDirectory(t),
|
|
}
|
|
err = conf.Fill()
|
|
require.NoError(t, err)
|
|
|
|
moneroCli, err := monero.CreateSpendWalletFromKeys(conf, kp, 0)
|
|
require.NoError(t, err)
|
|
height, err := moneroCli.GetHeight()
|
|
require.NoError(t, err)
|
|
xmrAmt := coins.StrToDecimal("1")
|
|
pnAmt := coins.MoneroToPiconero(xmrAmt)
|
|
monero.MineMinXMRBalance(t, moneroCli, pnAmt)
|
|
|
|
kp2, err := mcrypto.GenerateKeys()
|
|
require.NoError(t, err)
|
|
depositAddr := kp2.PublicKeyPair().Address(env)
|
|
|
|
err = ClaimMonero(
|
|
context.Background(),
|
|
common.Development,
|
|
[32]byte{},
|
|
moneroCli,
|
|
height,
|
|
kp,
|
|
depositAddr,
|
|
false,
|
|
)
|
|
require.NoError(t, err)
|
|
}
|