Skip to content

Commit 47adc86

Browse files
committed
Cover fork.go
1 parent e47522a commit 47adc86

1 file changed

Lines changed: 67 additions & 0 deletions

File tree

pkg/dirksigner/fork_test.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package dirksigner
2+
3+
import (
4+
"bytes"
5+
"strings"
6+
"testing"
7+
8+
"github.com/jshufro/remote-signer-dirk-interop/internal/api"
9+
"github.com/jshufro/remote-signer-dirk-interop/internal/domains"
10+
"github.com/neilotoole/slogt"
11+
)
12+
13+
func TestCalculateDomain(t *testing.T) {
14+
dirk := DirkSigner{
15+
log: slogt.New(t),
16+
}
17+
domain, err := dirk.calculateDomain(domains.DomainAggregateAndProof, "0x0000000000000000000000000000000000000000000000000000000000000000", &api.Fork{
18+
CurrentVersion: "0x00000000",
19+
PreviousVersion: "0x00000000",
20+
})
21+
if err != nil {
22+
t.Fatalf("failed to calculate domain: %v", err)
23+
}
24+
expectedDomain := "06000000f5a5fd42d16a20302798ef6ed309979b43003d2320d9f0e8ea9831a9"
25+
expectedDomainBytes, err := decodeHex(expectedDomain)
26+
if err != nil {
27+
t.Fatalf("failed to decode expected domain: %v", err)
28+
}
29+
if !bytes.Equal(domain, expectedDomainBytes) {
30+
t.Fatalf("domain is not correct: %x", domain)
31+
}
32+
33+
// Invalid genesis validator root should produce an error
34+
_, err = dirk.calculateDomain(domains.DomainAggregateAndProof, "0xgg", &api.Fork{
35+
CurrentVersion: "0x00000000",
36+
PreviousVersion: "0x00000000",
37+
})
38+
if err == nil {
39+
t.Fatalf("expected error, got nil")
40+
}
41+
_, err = dirk.calculateDomain(domains.DomainAggregateAndProof, "0x12", &api.Fork{
42+
CurrentVersion: "0x00000000",
43+
PreviousVersion: "0x00000000",
44+
})
45+
if err == nil {
46+
t.Fatalf("expected error, got nil")
47+
}
48+
49+
// Invalid current version should produce an error
50+
_, err = dirk.calculateDomain(domains.DomainAggregateAndProof, "0x0000000000000000000000000000000000000000000000000000000000000000", &api.Fork{
51+
CurrentVersion: "0x1234567890",
52+
PreviousVersion: "0x00000000",
53+
})
54+
if err == nil {
55+
t.Fatalf("expected error, got nil")
56+
}
57+
if !strings.Contains(err.Error(), "fork version is not 4 bytes") {
58+
t.Fatalf("error is not correct: %v", err)
59+
}
60+
_, err = dirk.calculateDomain(domains.DomainAggregateAndProof, "0x0000000000000000000000000000000000000000000000000000000000000000", &api.Fork{
61+
CurrentVersion: "0xgg",
62+
PreviousVersion: "0x00000000",
63+
})
64+
if err == nil {
65+
t.Fatalf("expected error, got nil")
66+
}
67+
}

0 commit comments

Comments
 (0)