package types_test

import (
	"encoding/hex"
	"testing"

	"github.com/stretchr/testify/require"

	feedstypes "github.com/bandprotocol/chain/v3/x/feeds/types"
	"github.com/bandprotocol/chain/v3/x/tunnel/types"
)

func TestEncodeTSSFixedPrice(t *testing.T) {
	expectedMsg := ("cba0ad5a" +
		"0000000000000000000000000000000000000000000000000000000000000020" +
		"0000000000000000000000000000000000000000000000000000000000000003" +
		"0000000000000000000000000000000000000000000000000000000000000060" +
		"000000000000000000000000000000000000000000000000000000000000007b" +
		"0000000000000000000000000000000000000000000000000000000000000001" +
		"00000000000000000000000000000000000000000043533a42414e442d555344" +
		"0000000000000000000000000000000000000000000000000000000000000002")

	msg, err := types.EncodeTSS(
		3,
		[]feedstypes.Price{
			{SignalID: "CS:BAND-USD", Price: 2, Status: feedstypes.PRICE_STATUS_AVAILABLE},
		},
		123,
		feedstypes.ENCODER_FIXED_POINT_ABI,
	)
	require.NoError(t, err)

	require.Equal(t, expectedMsg, hex.EncodeToString(msg))
}

func TestEncodeTSSTick(t *testing.T) {
	expectedMsg := ("db99b2b3" +
		"0000000000000000000000000000000000000000000000000000000000000020" +
		"0000000000000000000000000000000000000000000000000000000000000003" +
		"0000000000000000000000000000000000000000000000000000000000000060" +
		"000000000000000000000000000000000000000000000000000000000000007b" +
		"0000000000000000000000000000000000000000000000000000000000000001" +
		"00000000000000000000000000000000000000000043533a42414e442d555344" +
		"000000000000000000000000000000000000000000000000000000000000f188")

	msg, err := types.EncodeTSS(
		3,
		[]feedstypes.Price{
			{SignalID: "CS:BAND-USD", Price: 2, Status: feedstypes.PRICE_STATUS_AVAILABLE},
		},
		123,
		feedstypes.ENCODER_TICK_ABI,
	)
	require.NoError(t, err)

	require.Equal(t, expectedMsg, hex.EncodeToString(msg))
}
