signatureArchives_test.go 1.31 KB
Newer Older
Caro Axel's avatar
Caro Axel committed
1 2 3 4 5
package entities

import (
	"testing"

6
	"github.com/stretchr/testify/assert"
Caro Axel's avatar
Caro Axel committed
7 8 9 10 11 12
)

func TestArePromisesEqual(t *testing.T) {
	promise0 := NewPromise(uint32(1), uint32(0), uint32(0))
	promise1 := NewPromise(uint32(0), uint32(1), uint32(1))

ElyKar's avatar
ElyKar committed
13
	equal := promise0.Equal(promise1)
Caro Axel's avatar
Caro Axel committed
14 15 16
	assert.Equal(t, equal, false)

	promise1.RecipientKeyIndex = uint32(1)
ElyKar's avatar
ElyKar committed
17
	equal = promise0.Equal(promise1)
Caro Axel's avatar
Caro Axel committed
18 19 20
	assert.Equal(t, equal, false)

	promise1.SenderKeyIndex = uint32(0)
ElyKar's avatar
ElyKar committed
21
	equal = promise0.Equal(promise1)
Caro Axel's avatar
Caro Axel committed
22 23 24
	assert.Equal(t, equal, false)

	promise1.SequenceIndex = uint32(0)
ElyKar's avatar
ElyKar committed
25
	equal = promise0.Equal(promise1)
Caro Axel's avatar
Caro Axel committed
26 27
	assert.Equal(t, equal, true)
}
Caro Axel's avatar
Caro Axel committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50

func TestContainsSigner(t *testing.T) {
	archives := NewSignatureArchives(signatureUUIDBson, sequence, signersEntities, contractDocumentHash, seal)
	badHash := []byte{}
	present, index := archives.ContainsSigner(badHash)
	assert.False(t, present)
	assert.Equal(t, uint32(0), index)

	badHash = []byte{0, 0, 7}
	present, index = archives.ContainsSigner(badHash)
	assert.False(t, present)
	assert.Equal(t, uint32(0), index)

	goodHash := signersEntities[0].Hash
	present, index = archives.ContainsSigner(goodHash)
	assert.True(t, present)
	assert.Equal(t, uint32(0), index)

	goodHash = signersEntities[1].Hash
	present, index = archives.ContainsSigner(goodHash)
	assert.True(t, present)
	assert.Equal(t, uint32(1), index)
}