// Copyright Fuzamei Corp. 2018 All Rights Reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package executor

import (
	"testing"

	mixTy "github.com/33cn/plugin/plugin/dapp/mix/types"
	"github.com/stretchr/testify/assert"
)

/*
leaf0 = "16308793397024662832064523892418908145900866571524124093537199035808550255649"
hash 4010939160279929375357088561050093294975728828994381439611270589357856115894

leaf1 = 21467822781369104390668289189963532506973289112396605437823854946060028754354
leaf hash 19846868408490658463513283235031798083935100648624648285566873440653365397815

leaf2= 4178471437305290899835614805415999986197321812505352791035422725360758750328
leaf hash 4062509694129705639089082212179777344962624935939361647381392834235969534831

leaf3= 10407830929890509544473717262275616077696950294748419792758056545898949331744
leaf hash 3656010751855274388516368747583374746848682779395325737100877017850943546836

leaf4= 11032604436245646157001636966356016502073301224837385665550497706958264582086
leaf hash 5949485921924623528448830799540295699445001672535082168235329176256394356669

 merkleroot= 6988991286454436061784929049510388415076132311642532433013500389938249229356
0 proof str= 21467822781369104390668289189963532506973289112396605437823854946060028754354
1 proof str= 12096317366724227951683802305909172775715878134489527031786909074403605889217
2 proof str= 14541527209424185878803689752018034974129079647509824805270353433359922459228
3 proof str= 16581570556767364549626991605903512613557832602774591000372759906303762837296
*/

func TestGetProveData(t *testing.T) {
	leaves := []string{
		"16308793397024662832064523892418908145900866571524124093537199035808550255649",
		"21467822781369104390668289189963532506973289112396605437823854946060028754354",
		"4178471437305290899835614805415999986197321812505352791035422725360758750328",
		"10407830929890509544473717262275616077696950294748419792758056545898949331744",
		"11032604436245646157001636966356016502073301224837385665550497706958264582086",
	}

	proves := []string{
		"21467822781369104390668289189963532506973289112396605437823854946060028754354",
		"367337696696422936865919560478589243810446804477597373440139066420957868266",
		"5538594811879266165080692952618163249542275094298127431082963485737222728396",
		"143025316472030670451892215893941356364968202515180811944684799652132907215",
	}

	var leave [][]byte
	for _, l := range leaves {
		leave = append(leave, mixTy.Str2Byte(l))
	}

	ret, err := getProveData(leave[1], leave)
	assert.Nil(t, err)
	assert.Equal(t, uint32(5), ret.NumLeaves)
	assert.Equal(t, uint32(1), ret.ProofIndex)
	assert.Equal(t, "2857051084155588640772960772751117206153267452172716633910046945631762242957", ret.RootHash)
	assert.Equal(t, len(proves), len(ret.ProofSet))
	for i, k := range proves {
		assert.Equal(t, k, ret.ProofSet[i])
	}
	assert.Equal(t, []uint32([]uint32{0, 1, 1}), ret.Helpers)

}
