|
4 | 4 | "testing" |
5 | 5 |
|
6 | 6 | "github.com/filecoin-project/go-f3/gpbft" |
| 7 | + "github.com/stretchr/testify/assert" |
7 | 8 | "github.com/stretchr/testify/require" |
8 | 9 | ) |
9 | 10 |
|
@@ -107,3 +108,79 @@ func TestECChain(t *testing.T) { |
107 | 108 | require.Equal(t, second[1], gpbft.TipSet{Epoch: 1, Key: []byte{2}}) |
108 | 109 | }) |
109 | 110 | } |
| 111 | + |
| 112 | +func TestECChain_Eq(t *testing.T) { |
| 113 | + t.Parallel() |
| 114 | + var ( |
| 115 | + commitThis = [32]byte{0x01} |
| 116 | + commitThat = [32]byte{0x02} |
| 117 | + ptThis = gpbft.MakeCid([]byte("fish")) |
| 118 | + ptThat = gpbft.MakeCid([]byte("lobster")) |
| 119 | + ts1 = gpbft.TipSet{Epoch: 1, Key: []byte("barreleye1"), PowerTable: ptThat, Commitments: commitThis} |
| 120 | + ts2 = gpbft.TipSet{Epoch: 2, Key: []byte("barreleye2"), PowerTable: ptThat, Commitments: commitThis} |
| 121 | + ts3 = gpbft.TipSet{Epoch: 3, Key: []byte("barreleye3"), PowerTable: ptThat, Commitments: commitThis} |
| 122 | + ts1DifferentCommitments = gpbft.TipSet{1, []byte("barreleye1"), ptThat, commitThat} |
| 123 | + ts1DifferentPowerTable = gpbft.TipSet{1, []byte("barreleye1"), ptThis, commitThis} |
| 124 | + ) |
| 125 | + for _, tt := range []struct { |
| 126 | + name string |
| 127 | + one *gpbft.ECChain |
| 128 | + other *gpbft.ECChain |
| 129 | + expect bool |
| 130 | + }{ |
| 131 | + { |
| 132 | + name: "Equal chains", |
| 133 | + one: &gpbft.ECChain{ts1, ts2}, |
| 134 | + other: &gpbft.ECChain{ts1, ts2}, |
| 135 | + expect: true, |
| 136 | + }, |
| 137 | + { |
| 138 | + name: "Different chains", |
| 139 | + one: &gpbft.ECChain{ts1, ts2}, |
| 140 | + other: &gpbft.ECChain{ts1, ts3}, |
| 141 | + expect: false, |
| 142 | + }, |
| 143 | + { |
| 144 | + name: "Same chain compared with itself", |
| 145 | + one: &gpbft.ECChain{ts1, ts2}, |
| 146 | + other: &gpbft.ECChain{ts1, ts2}, |
| 147 | + expect: true, |
| 148 | + }, |
| 149 | + { |
| 150 | + name: "Different lengths", |
| 151 | + one: &gpbft.ECChain{ts1}, |
| 152 | + other: &gpbft.ECChain{ts1, ts2}, |
| 153 | + expect: false, |
| 154 | + }, |
| 155 | + { |
| 156 | + name: "Zero chains (empty chains)", |
| 157 | + one: &gpbft.ECChain{}, |
| 158 | + other: &gpbft.ECChain{}, |
| 159 | + expect: true, |
| 160 | + }, |
| 161 | + { |
| 162 | + name: "One zero chain", |
| 163 | + one: &gpbft.ECChain{ts1}, |
| 164 | + other: &gpbft.ECChain{}, |
| 165 | + expect: false, |
| 166 | + }, |
| 167 | + { |
| 168 | + name: "Different commitments", |
| 169 | + one: &gpbft.ECChain{ts1}, |
| 170 | + other: &gpbft.ECChain{ts1DifferentCommitments}, |
| 171 | + expect: false, |
| 172 | + }, |
| 173 | + { |
| 174 | + name: "Different power table", |
| 175 | + one: &gpbft.ECChain{ts1}, |
| 176 | + other: &gpbft.ECChain{ts1DifferentPowerTable}, |
| 177 | + expect: false, |
| 178 | + }, |
| 179 | + } { |
| 180 | + t.Run(tt.name, func(t *testing.T) { |
| 181 | + t.Parallel() |
| 182 | + assert.Equal(t, tt.expect, tt.one.Eq(*tt.other), "Unexpected equality result for one compared to other: %s", tt.name) |
| 183 | + assert.Equal(t, tt.expect, tt.other.Eq(*tt.one), "Unexpected equality result for other compared to one: %s", tt.name) |
| 184 | + }) |
| 185 | + } |
| 186 | +} |
0 commit comments