|
| 1 | +// Copyright 2025 Blink Labs Software |
| 2 | +// |
| 3 | +// Use of this source code is governed by an MIT-style |
| 4 | +// license that can be found in the LICENSE file or at |
| 5 | +// https://opensource.org/licenses/MIT. |
| 6 | + |
| 7 | +package handshake_test |
| 8 | + |
| 9 | +import ( |
| 10 | + "net" |
| 11 | + "reflect" |
| 12 | + "testing" |
| 13 | + |
| 14 | + "github.com/blinklabs-io/cdnsd/internal/handshake" |
| 15 | +) |
| 16 | + |
| 17 | +func TestCovenantRegisterFromGeneric(t *testing.T) { |
| 18 | + // This data comes from mainnet TX 63ba84b6362724aa8fd484d3616c8d1bdea68240c8e0cd6a104fcf85a35d52fb |
| 19 | + testGenericCovenant := &handshake.GenericCovenant{ |
| 20 | + Type: handshake.CovenantTypeRegister, |
| 21 | + Items: [][]byte{ |
| 22 | + decodeHex("62a90ce374b1499d0b67b1e4e6164b18acacbd16be905a6ffee593d48d4e0a82"), |
| 23 | + decodeHex("8d1e0400"), |
| 24 | + decodeHex("0002036e73310a69727677696c6c69616d002ce706b701c00202036e7332c00636d688f601c01a00d5580d0114402ed0125506f35ba249265f39b988d7028a28c300d5580d02200c6c45064c26b529b4ac074dff5de60a99d6025d5b0d7f32c2b8c7d40ec8b3de00d5580d043071cb0417852b08b965413f3b871b033996159d121a585e35111a335d4cfb79b67e49a99c3829f6a1f42e100f7f33d7d9"), |
| 25 | + decodeHex("0000000000000000153c62dbcabb762c254fb4104ab7cdd779926b79b34601fc"), |
| 26 | + }, |
| 27 | + } |
| 28 | + expectedCovenant := &handshake.RegisterCovenant{ |
| 29 | + NameHash: decodeHex("62a90ce374b1499d0b67b1e4e6164b18acacbd16be905a6ffee593d48d4e0a82"), |
| 30 | + Height: 269965, |
| 31 | + ResourceData: handshake.DomainResourceData{ |
| 32 | + Version: 0, |
| 33 | + Records: []handshake.DomainRecord{ |
| 34 | + &handshake.Glue4DomainRecord{ |
| 35 | + Name: "ns1.irvwilliam.", |
| 36 | + Address: net.ParseIP("44.231.6.183").To4(), |
| 37 | + }, |
| 38 | + &handshake.NsDomainRecord{ |
| 39 | + Name: "ns1.irvwilliam.", |
| 40 | + }, |
| 41 | + &handshake.Glue4DomainRecord{ |
| 42 | + Name: "ns2.irvwilliam.", |
| 43 | + Address: net.ParseIP("54.214.136.246").To4(), |
| 44 | + }, |
| 45 | + &handshake.NsDomainRecord{ |
| 46 | + Name: "ns2.irvwilliam.", |
| 47 | + }, |
| 48 | + &handshake.DsDomainRecord{ |
| 49 | + KeyTag: 54616, |
| 50 | + Algorithm: 13, |
| 51 | + DigestType: 1, |
| 52 | + Digest: decodeHex("402ed0125506f35ba249265f39b988d7028a28c3"), |
| 53 | + }, |
| 54 | + &handshake.DsDomainRecord{ |
| 55 | + KeyTag: 54616, |
| 56 | + Algorithm: 13, |
| 57 | + DigestType: 2, |
| 58 | + Digest: decodeHex("0c6c45064c26b529b4ac074dff5de60a99d6025d5b0d7f32c2b8c7d40ec8b3de"), |
| 59 | + }, |
| 60 | + &handshake.DsDomainRecord{ |
| 61 | + KeyTag: 54616, |
| 62 | + Algorithm: 13, |
| 63 | + DigestType: 4, |
| 64 | + Digest: decodeHex("71cb0417852b08b965413f3b871b033996159d121a585e35111a335d4cfb79b67e49a99c3829f6a1f42e100f7f33d7d9"), |
| 65 | + }, |
| 66 | + }, |
| 67 | + }, |
| 68 | + BlockHash: decodeHex("0000000000000000153c62dbcabb762c254fb4104ab7cdd779926b79b34601fc"), |
| 69 | + } |
| 70 | + tmpCovenant, err := handshake.NewRegisterCovenantFromGeneric(testGenericCovenant) |
| 71 | + if err != nil { |
| 72 | + t.Fatalf("unexpected error creating RegisterCovenant from GenericCovenant: %s", err) |
| 73 | + } |
| 74 | + if !reflect.DeepEqual(tmpCovenant, expectedCovenant) { |
| 75 | + t.Fatalf( |
| 76 | + "did not get expected covenant:\n got: %#v\n wanted: %#v", |
| 77 | + tmpCovenant, |
| 78 | + expectedCovenant, |
| 79 | + ) |
| 80 | + } |
| 81 | +} |
| 82 | + |
| 83 | +func TestCovenantUpdateFromGeneric(t *testing.T) { |
| 84 | + // This data comes from mainnet TX 63ba84b6362724aa8fd484d3616c8d1bdea68240c8e0cd6a104fcf85a35d52fb |
| 85 | + testGenericCovenant := &handshake.GenericCovenant{ |
| 86 | + Type: handshake.CovenantTypeUpdate, |
| 87 | + Items: [][]byte{ |
| 88 | + decodeHex("62a90ce374b1499d0b67b1e4e6164b18acacbd16be905a6ffee593d48d4e0a82"), |
| 89 | + decodeHex("8d1e0400"), |
| 90 | + decodeHex("0002036e73310a69727677696c6c69616d002ce706b701c00202036e7332c00636d688f601c01a00d5580d0114402ed0125506f35ba249265f39b988d7028a28c300d5580d02200c6c45064c26b529b4ac074dff5de60a99d6025d5b0d7f32c2b8c7d40ec8b3de00d5580d043071cb0417852b08b965413f3b871b033996159d121a585e35111a335d4cfb79b67e49a99c3829f6a1f42e100f7f33d7d9"), |
| 91 | + decodeHex("0000000000000000153c62dbcabb762c254fb4104ab7cdd779926b79b34601fc"), |
| 92 | + }, |
| 93 | + } |
| 94 | + expectedCovenant := &handshake.UpdateCovenant{ |
| 95 | + NameHash: decodeHex("62a90ce374b1499d0b67b1e4e6164b18acacbd16be905a6ffee593d48d4e0a82"), |
| 96 | + Height: 269965, |
| 97 | + ResourceData: handshake.DomainResourceData{ |
| 98 | + Version: 0, |
| 99 | + Records: []handshake.DomainRecord{ |
| 100 | + &handshake.Glue4DomainRecord{ |
| 101 | + Name: "ns1.irvwilliam.", |
| 102 | + Address: net.ParseIP("44.231.6.183").To4(), |
| 103 | + }, |
| 104 | + &handshake.NsDomainRecord{ |
| 105 | + Name: "ns1.irvwilliam.", |
| 106 | + }, |
| 107 | + &handshake.Glue4DomainRecord{ |
| 108 | + Name: "ns2.irvwilliam.", |
| 109 | + Address: net.ParseIP("54.214.136.246").To4(), |
| 110 | + }, |
| 111 | + &handshake.NsDomainRecord{ |
| 112 | + Name: "ns2.irvwilliam.", |
| 113 | + }, |
| 114 | + &handshake.DsDomainRecord{ |
| 115 | + KeyTag: 54616, |
| 116 | + Algorithm: 13, |
| 117 | + DigestType: 1, |
| 118 | + Digest: decodeHex("402ed0125506f35ba249265f39b988d7028a28c3"), |
| 119 | + }, |
| 120 | + &handshake.DsDomainRecord{ |
| 121 | + KeyTag: 54616, |
| 122 | + Algorithm: 13, |
| 123 | + DigestType: 2, |
| 124 | + Digest: decodeHex("0c6c45064c26b529b4ac074dff5de60a99d6025d5b0d7f32c2b8c7d40ec8b3de"), |
| 125 | + }, |
| 126 | + &handshake.DsDomainRecord{ |
| 127 | + KeyTag: 54616, |
| 128 | + Algorithm: 13, |
| 129 | + DigestType: 4, |
| 130 | + Digest: decodeHex("71cb0417852b08b965413f3b871b033996159d121a585e35111a335d4cfb79b67e49a99c3829f6a1f42e100f7f33d7d9"), |
| 131 | + }, |
| 132 | + }, |
| 133 | + }, |
| 134 | + BlockHash: decodeHex("0000000000000000153c62dbcabb762c254fb4104ab7cdd779926b79b34601fc"), |
| 135 | + } |
| 136 | + tmpCovenant, err := handshake.NewUpdateCovenantFromGeneric(testGenericCovenant) |
| 137 | + if err != nil { |
| 138 | + t.Fatalf("unexpected error creating UpdateCovenant from GenericCovenant: %s", err) |
| 139 | + } |
| 140 | + if !reflect.DeepEqual(tmpCovenant, expectedCovenant) { |
| 141 | + t.Fatalf( |
| 142 | + "did not get expected covenant:\n got: %#v\n wanted: %#v", |
| 143 | + tmpCovenant, |
| 144 | + expectedCovenant, |
| 145 | + ) |
| 146 | + } |
| 147 | +} |
0 commit comments