oracle_python_test.go 814 B

123456789101112131415161718192021222324252627282930313233343536
  1. package protocol_test
  2. import (
  3. "encoding/hex"
  4. "os"
  5. "os/exec"
  6. "path/filepath"
  7. "strings"
  8. "testing"
  9. "hth/internal/protocol"
  10. "hth/internal/testutil"
  11. )
  12. func TestIndependentPythonOracleMatchesGoSETALL(t *testing.T) {
  13. py := os.Getenv("PYTHON")
  14. if py == "" {
  15. py = "python3"
  16. }
  17. oracle := filepath.Join(testutil.HostRoot(t), "tools", "protocol_oracle.py")
  18. out, err := exec.Command(py, oracle, "--encode-demo").CombinedOutput()
  19. if err != nil {
  20. t.Fatalf("oracle: %v %s", err, out)
  21. }
  22. got, err := hex.DecodeString(strings.TrimSpace(string(out)))
  23. if err != nil {
  24. t.Fatal(err, string(out))
  25. }
  26. want, err := protocol.SetAll{Fan: [4]uint8{10, 10, 10, 10}}.Encode()
  27. if err != nil {
  28. t.Fatal(err)
  29. }
  30. if hex.EncodeToString(got) != hex.EncodeToString(want) {
  31. t.Fatalf("oracle %x != go %x", got, want)
  32. }
  33. }