6 "github.com/stretchr/testify/assert"
8 cmn "github.com/tendermint/tmlibs/common"
22 // TestECCPasses makes sure that the AddECC/CheckECC methods are symetric
23 func TestECCPasses(t *testing.T) {
24 assert := assert.New(t)
26 checks := append(codecs, NoECC{})
28 for _, check := range checks {
29 for i := 0; i < 2000; i++ {
30 numBytes := cmn.RandInt()%60 + 1
31 data := cmn.RandBytes(numBytes)
33 checked := check.AddECC(data)
34 res, err := check.CheckECC(checked)
35 if assert.Nil(err, "%#v: %+v", check, err) {
36 assert.Equal(data, res, "%v", check)
42 // TestECCFails makes sure random data will (usually) fail the checksum
43 func TestECCFails(t *testing.T) {
44 assert := assert.New(t)
49 for _, check := range checks {
51 for i := 0; i < attempts; i++ {
52 numBytes := cmn.RandInt()%60 + 1
53 data := cmn.RandBytes(numBytes)
54 _, err := check.CheckECC(data)
59 // we allow up to 1 falsely accepted checksums, as there are random matches
60 assert.InDelta(attempts, failed, 1, "%v", check)