package spam import ( "git.mascherari.press/cwtch/protocol" "github.com/golang/protobuf/proto" "github.com/s-rah/go-ricochet/wire/control" "testing" ) func TestSpamGuard(t *testing.T) { var spamGuard Guard spamGuard.Difficulty = 2 challenge := spamGuard.GenerateChallenge(3) control := new(Protocol_Data_Control.Packet) proto.Unmarshal(challenge[:], control) if control.GetChannelResult() != nil { ce, _ := proto.GetExtension(control.GetChannelResult(), protocol.E_ServerNonce) challenge := ce.([]byte)[:] sgsolve := spamGuard.SolveChallenge(challenge, []byte("Hello")) t.Logf("Solved: %v %v", challenge, sgsolve) result := spamGuard.ValidateChallenge([]byte("Hello"), sgsolve) if result != true { t.Errorf("Validating Guard Failed") } return } t.Errorf("Failed SpamGaurd") }