package moneroutil

import (
	"bytes"
	"encoding/hex"
	"testing"
)

func TestVerifyRctSimple(t *testing.T) {
	tests := []struct {
		name           string
		inputOutpoints [][]string
		txHex          string
	}{
		{
			name: "be9d2cf9b473dbbb2c59ffb07b5d812516f94d64121d87ad61956386a4bc3843",
			inputOutpoints: [][]string{
				{
					"edfd415247d3e5e6eb4a7d65d4b25026cdea1b5595f0ea42ed56b8e640310169",
					"8d073256bbfcd190b56c7e2d69302bfef0f2dcfe58c04349f95f3ed8310e9ffe",
					"38ea121a03ab1bae88357a88cdaa5727f6f5cf1d9e287efe33571ba9e2bc9ea6",
				},
				{
					"c9afb7de7bfb5d9bb5a593c969b4b93dab59db4ca05e20966b023fbb2cac4f88",
					"12c5128ecde3c358528236ccb62bffc04a83471802eba04d94ec01d150c4ebf1",
					"aa5b77ea8c2d23bf282fd20e70c234af618769f22afbbb100f084bd25ec8f1a4",
				},
			},
			txHex: "[encoded data, 39122 characters]",
		},
		{
			name:  "3 more inputs from 1302238",
			txHex: "[encoded data, 39122 characters]",
		},
	}
	for _, test := range tests {
		serializedTx, _ := hex.DecodeString(test.txHex)
		buffer := new(bytes.Buffer)
		buffer.Write(serializedTx)
		transaction, err := ParseTransaction(buffer)
		if err != nil {
			t.Errorf("%s: error parsing tx: %s", test.name, err)
		}
		if !transaction.rctSignature.VerifyRctSimple() {
			t.Errorf("%s: not verified", test.name)
		}
		pubkeys := make([][]CtKey, len(test.inputOutpoints))
		for i, outPoint := range test.inputOutpoints {
			pubkeys[i] = make([]CtKey, len(outPoint))
			for j, point := range outPoint {
				pubkeys[i][j] = CtKey{
					destination: HexToKey(point),
				}
			}
		}
		transaction.ExpandTransaction(pubkeys)
	}
}
