|
17 | 17 | package agreement |
18 | 18 |
|
19 | 19 | import ( |
20 | | - "encoding/base64" |
21 | 20 | "testing" |
22 | 21 |
|
23 | 22 | "github.com/stretchr/testify/require" |
24 | 23 |
|
25 | 24 | "github.com/algorand/go-algorand/crypto" |
26 | 25 | "github.com/algorand/go-algorand/data/basics" |
27 | 26 | "github.com/algorand/go-algorand/data/committee" |
28 | | - "github.com/algorand/go-algorand/network" |
29 | 27 | "github.com/algorand/go-algorand/protocol" |
30 | | - "github.com/algorand/go-algorand/test/partitiontest" |
31 | 28 | ) |
32 | 29 |
|
33 | 30 | var poolAddr = basics.Address{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff} |
@@ -83,52 +80,3 @@ func BenchmarkVoteDecoding(b *testing.B) { |
83 | 80 | decodeVote(msgBytes) |
84 | 81 | } |
85 | 82 | } |
86 | | - |
87 | | -// TestMessageBackwardCompatibility ensures MessageHandle field can be |
88 | | -// properly decoded from message. |
89 | | -// This test is only needed for agreement state serialization switch from reflection to msgp. |
90 | | -func TestMessageBackwardCompatibility(t *testing.T) { |
91 | | - partitiontest.PartitionTest(t) |
92 | | - |
93 | | - type messageMetadata struct { |
94 | | - raw network.IncomingMessage |
95 | | - } |
96 | | - |
97 | | - encoded, err := base64.StdEncoding.DecodeString("iaZCdW5kbGWAr0NvbXBvdW5kTWVzc2FnZYKoUHJvcG9zYWyApFZvdGWArU1lc3NhZ2VIYW5kbGWAqFByb3Bvc2FsgKNUYWeiUFC1VW5hdXRoZW50aWNhdGVkQnVuZGxlgLdVbmF1dGhlbnRpY2F0ZWRQcm9wb3NhbICzVW5hdXRoZW50aWNhdGVkVm90ZYCkVm90ZYA=") |
98 | | - require.NoError(t, err) |
99 | | - |
100 | | - // run on master f57a276 to get the encoded data for above |
101 | | - // msg := message{ |
102 | | - // MessageHandle: &messageMetadata{raw: network.IncomingMessage{Tag: protocol.Tag("mytag"), Data: []byte("some data")}}, |
103 | | - // Tag: protocol.ProposalPayloadTag, |
104 | | - // } |
105 | | - |
106 | | - // result := protocol.EncodeReflect(&msg) |
107 | | - // fmt.Println(base64.StdEncoding.EncodeToString(result)) |
108 | | - |
109 | | - // messages for all rounds after this change should not have MessageHandle set so clearing it out and re-encoding/decoding it should yield this |
110 | | - targetMessage := message{ |
111 | | - Tag: protocol.ProposalPayloadTag, |
112 | | - } |
113 | | - |
114 | | - require.Containsf(t, string(encoded), "MessageHandle", "encoded message does not contain MessageHandle field") |
115 | | - var m1, m2, m3, m4 message |
116 | | - // Both msgp and reflection should decode the message containing old MessageHandle successfully |
117 | | - err = protocol.Decode(encoded, &m1) |
118 | | - require.NoError(t, err) |
119 | | - err = protocol.DecodeReflect(encoded, &m2) |
120 | | - require.NoError(t, err) |
121 | | - // after setting MessageHandle to nil both should re-encode and decode to same values |
122 | | - m1.MessageHandle = nil |
123 | | - m2.MessageHandle = nil |
124 | | - e1 := protocol.Encode(&m1) |
125 | | - e2 := protocol.EncodeReflect(&m2) |
126 | | - require.Equal(t, e1, e2) |
127 | | - require.NotContainsf(t, string(e1), "MessageHandle", "encoded message still contains MessageHandle field") |
128 | | - err = protocol.DecodeReflect(e1, &m3) |
129 | | - require.NoError(t, err) |
130 | | - err = protocol.Decode(e2, &m4) |
131 | | - require.NoError(t, err) |
132 | | - require.Equal(t, m3, m4) |
133 | | - require.Equal(t, m3, targetMessage) |
134 | | -} |
0 commit comments