]> Cypherpunks.ru repositories - nncp.git/blobdiff - src/toss_test.go
MTH
[nncp.git] / src / toss_test.go
index d269141cc5ca199b015f5e50e74375178ab0a6c9..e2b3145e988e47d8541eb6a5bf4625fbc4d5b4d6 100644 (file)
@@ -31,7 +31,6 @@ import (
        "testing/quick"
 
        xdr "github.com/davecgh/go-xdr/xdr2"
-       "golang.org/x/crypto/blake2b"
 )
 
 var (
@@ -99,6 +98,8 @@ func TestTossExec(t *testing.T) {
                                []string{"arg0", "arg1"},
                                strings.NewReader("BODY\n"),
                                1<<15,
+                               false,
+                               false,
                        ); err != nil {
                                t.Error(err)
                                return false
@@ -188,8 +189,9 @@ func TestTossFile(t *testing.T) {
                ctx.Neigh[*nodeOur.Id] = nodeOur.Their()
                incomingPath := filepath.Join(spool, "incoming")
                for _, fileData := range files {
-                       checksum := blake2b.Sum256(fileData)
-                       fileName := Base32Codec.EncodeToString(checksum[:])
+                       hasher := MTHNew(0, 0)
+                       hasher.Write(fileData)
+                       fileName := Base32Codec.EncodeToString(hasher.Sum(nil))
                        src := filepath.Join(spool, fileName)
                        if err := ioutil.WriteFile(src, fileData, os.FileMode(0600)); err != nil {
                                panic(err)
@@ -219,8 +221,9 @@ func TestTossFile(t *testing.T) {
                        return false
                }
                for _, fileData := range files {
-                       checksum := blake2b.Sum256(fileData)
-                       fileName := Base32Codec.EncodeToString(checksum[:])
+                       hasher := MTHNew(0, 0)
+                       hasher.Write(fileData)
+                       fileName := Base32Codec.EncodeToString(hasher.Sum(nil))
                        data, err := ioutil.ReadFile(filepath.Join(incomingPath, fileName))
                        if err != nil {
                                panic(err)
@@ -381,7 +384,12 @@ func TestTossFreq(t *testing.T) {
                }
                for job := range ctx.Jobs(ctx.Self.Id, TTx) {
                        var buf bytes.Buffer
-                       _, _, err := PktEncRead(ctx.Self, ctx.Neigh, job.Fd, &buf)
+                       fd, err := os.Open(job.Path)
+                       if err != nil {
+                               t.Error(err)
+                               return false
+                       }
+                       _, _, err = PktEncRead(ctx.Self, ctx.Neigh, fd, &buf)
                        if err != nil {
                                t.Error(err)
                                return false
@@ -448,12 +456,11 @@ func TestTossTrns(t *testing.T) {
                        pktTrans := Pkt{
                                Magic:   MagicNNCPPv3,
                                Type:    PktTypeTrns,
-                               PathLen: blake2b.Size256,
-                               Path:    new([MaxPathSize]byte),
+                               PathLen: MTHSize,
                        }
                        copy(pktTrans.Path[:], nodeOur.Id[:])
                        var dst bytes.Buffer
-                       if err := PktEncWrite(
+                       if _, err := PktEncWrite(
                                ctx.Self,
                                ctx.Neigh[*nodeOur.Id],
                                &pktTrans,
@@ -466,9 +473,10 @@ func TestTossTrns(t *testing.T) {
                                t.Error(err)
                                return false
                        }
-                       checksum := blake2b.Sum256(dst.Bytes())
+                       hasher := MTHNew(0, 0)
+                       hasher.Write(dst.Bytes())
                        if err := ioutil.WriteFile(
-                               filepath.Join(rxPath, Base32Codec.EncodeToString(checksum[:])),
+                               filepath.Join(rxPath, Base32Codec.EncodeToString(hasher.Sum(nil))),
                                dst.Bytes(),
                                os.FileMode(0600),
                        ); err != nil {