|
24 | 24 | import static com.hedera.node.app.hapi.utils.ethereum.TestingConstants.TRUFFLE0_PRIVATE_ECDSA_KEY;
|
25 | 25 | import static com.hedera.node.app.hapi.utils.ethereum.TestingConstants.TRUFFLE0_PUBLIC_ECDSA_KEY;
|
26 | 26 | import static com.hedera.node.app.hapi.utils.ethereum.TestingConstants.TRUFFLE1_ADDRESS;
|
27 |
| -import static com.hedera.node.app.hapi.utils.ethereum.TestingConstants.TRUFFLE1_PRIVATE_ECDSA_KEY; |
28 | 27 | import static com.hedera.node.app.hapi.utils.ethereum.TestingConstants.ZERO_BYTES;
|
29 | 28 | import static com.hedera.node.app.service.evm.utils.EthSigsUtils.recoverAddressFromPubKey;
|
30 | 29 | import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
31 |
| -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
32 |
| -import static org.junit.jupiter.api.Assertions.assertEquals; |
33 |
| -import static org.junit.jupiter.api.Assertions.assertNotEquals; |
34 |
| -import static org.junit.jupiter.api.Assertions.assertNotNull; |
35 | 30 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
36 | 31 |
|
37 | 32 | import com.swirlds.common.utility.CommonUtils;
|
@@ -96,207 +91,6 @@ public byte[] nextBytes(final int n) {
|
96 | 91 | return ans;
|
97 | 92 | }
|
98 | 93 |
|
99 |
| - @Test |
100 |
| - void signsLegacyUnprotectedNull() { |
101 |
| - final var tx = new EthTxData( |
102 |
| - null, |
103 |
| - LEGACY_ETHEREUM, |
104 |
| - null, |
105 |
| - 1, |
106 |
| - TINYBARS_57_IN_WEIBARS, |
107 |
| - TINYBARS_2_IN_WEIBARS, |
108 |
| - TINYBARS_57_IN_WEIBARS, |
109 |
| - 1_000_000L, |
110 |
| - TRUFFLE1_ADDRESS, |
111 |
| - BigInteger.ZERO, |
112 |
| - ZERO_BYTES, |
113 |
| - ZERO_BYTES, |
114 |
| - 1, |
115 |
| - new byte[0], |
116 |
| - new byte[0], |
117 |
| - new byte[0]); |
118 |
| - |
119 |
| - final EthTxData signedTx = EthTxSigs.signMessage(tx, TRUFFLE0_PRIVATE_ECDSA_KEY); |
120 |
| - |
121 |
| - assertArrayEquals(null, signedTx.chainId()); |
122 |
| - assertArrayEquals(new byte[] {27}, signedTx.v()); |
123 |
| - assertNotNull(tx.r()); |
124 |
| - assertNotNull(tx.s()); |
125 |
| - } |
126 |
| - |
127 |
| - @Test |
128 |
| - void signsLegacyUnprotectedZeroChainId() { |
129 |
| - final var tx = new EthTxData( |
130 |
| - null, |
131 |
| - LEGACY_ETHEREUM, |
132 |
| - ZERO_BYTES, |
133 |
| - 1, |
134 |
| - TINYBARS_57_IN_WEIBARS, |
135 |
| - TINYBARS_2_IN_WEIBARS, |
136 |
| - TINYBARS_57_IN_WEIBARS, |
137 |
| - 1_000_000L, |
138 |
| - TRUFFLE1_ADDRESS, |
139 |
| - BigInteger.ZERO, |
140 |
| - ZERO_BYTES, |
141 |
| - ZERO_BYTES, |
142 |
| - 1, |
143 |
| - new byte[0], |
144 |
| - new byte[0], |
145 |
| - new byte[0]); |
146 |
| - |
147 |
| - final EthTxData signedTx = EthTxSigs.signMessage(tx, TRUFFLE0_PRIVATE_ECDSA_KEY); |
148 |
| - |
149 |
| - Assertions.assertArrayEquals(ZERO_BYTES, signedTx.chainId()); |
150 |
| - assertArrayEquals(new byte[] {27}, signedTx.v()); |
151 |
| - assertNotNull(tx.r()); |
152 |
| - assertNotNull(tx.s()); |
153 |
| - } |
154 |
| - |
155 |
| - @Test |
156 |
| - void signsEIP2930() { |
157 |
| - final var tx = new EthTxData( |
158 |
| - null, |
159 |
| - EthTxData.EthTransactionType.EIP2930, |
160 |
| - ZERO_BYTES, |
161 |
| - 1, |
162 |
| - TINYBARS_57_IN_WEIBARS, |
163 |
| - TINYBARS_2_IN_WEIBARS, |
164 |
| - TINYBARS_57_IN_WEIBARS, |
165 |
| - 1_000_000L, |
166 |
| - TRUFFLE1_ADDRESS, |
167 |
| - BigInteger.ZERO, |
168 |
| - ZERO_BYTES, |
169 |
| - ZERO_BYTES, |
170 |
| - 1, |
171 |
| - new byte[0], |
172 |
| - new byte[0], |
173 |
| - new byte[0]); |
174 |
| - |
175 |
| - final EthTxData signedTx = EthTxSigs.signMessage(tx, TRUFFLE0_PRIVATE_ECDSA_KEY); |
176 |
| - |
177 |
| - assertNotNull(signedTx.r()); |
178 |
| - assertNotNull(signedTx.s()); |
179 |
| - } |
180 |
| - |
181 |
| - @Test |
182 |
| - void signsEIP1559() { |
183 |
| - final var tx = new EthTxData( |
184 |
| - null, |
185 |
| - EthTxData.EthTransactionType.EIP1559, |
186 |
| - ZERO_BYTES, |
187 |
| - 1, |
188 |
| - TINYBARS_57_IN_WEIBARS, |
189 |
| - TINYBARS_2_IN_WEIBARS, |
190 |
| - TINYBARS_57_IN_WEIBARS, |
191 |
| - 1_000_000L, |
192 |
| - TRUFFLE1_ADDRESS, |
193 |
| - BigInteger.ZERO, |
194 |
| - ZERO_BYTES, |
195 |
| - ZERO_BYTES, |
196 |
| - 1, |
197 |
| - new byte[0], |
198 |
| - new byte[0], |
199 |
| - new byte[0]); |
200 |
| - |
201 |
| - final EthTxData signedTx = EthTxSigs.signMessage(tx, TRUFFLE0_PRIVATE_ECDSA_KEY); |
202 |
| - |
203 |
| - assertNotNull(signedTx.r()); |
204 |
| - assertNotNull(signedTx.s()); |
205 |
| - } |
206 |
| - |
207 |
| - @Test |
208 |
| - void signsLegacyProtected() { |
209 |
| - final var tx = new EthTxData( |
210 |
| - null, |
211 |
| - LEGACY_ETHEREUM, |
212 |
| - CHAINID_TESTNET, |
213 |
| - 1, |
214 |
| - TINYBARS_57_IN_WEIBARS, |
215 |
| - TINYBARS_2_IN_WEIBARS, |
216 |
| - TINYBARS_57_IN_WEIBARS, |
217 |
| - 1_000_000L, |
218 |
| - TRUFFLE1_ADDRESS, |
219 |
| - BigInteger.ZERO, |
220 |
| - ZERO_BYTES, |
221 |
| - ZERO_BYTES, |
222 |
| - 1, |
223 |
| - new byte[0], |
224 |
| - new byte[0], |
225 |
| - new byte[0]); |
226 |
| - |
227 |
| - final EthTxData signedTx = EthTxSigs.signMessage(tx, TRUFFLE0_PRIVATE_ECDSA_KEY); |
228 |
| - |
229 |
| - Assertions.assertArrayEquals(CHAINID_TESTNET, signedTx.chainId()); |
230 |
| - assertArrayEquals(new byte[] {2, 116}, signedTx.v()); |
231 |
| - } |
232 |
| - |
233 |
| - @Test |
234 |
| - void extractAddress() { |
235 |
| - final var tx = new EthTxData( |
236 |
| - null, |
237 |
| - LEGACY_ETHEREUM, |
238 |
| - CHAINID_TESTNET, |
239 |
| - 1, |
240 |
| - TINYBARS_57_IN_WEIBARS, |
241 |
| - TINYBARS_2_IN_WEIBARS, |
242 |
| - TINYBARS_57_IN_WEIBARS, |
243 |
| - 1_000_000L, |
244 |
| - TRUFFLE1_ADDRESS, |
245 |
| - BigInteger.ZERO, |
246 |
| - ZERO_BYTES, |
247 |
| - ZERO_BYTES, |
248 |
| - 1, |
249 |
| - new byte[0], |
250 |
| - new byte[0], |
251 |
| - new byte[0]); |
252 |
| - |
253 |
| - final EthTxData signedTx = EthTxSigs.signMessage(tx, TRUFFLE0_PRIVATE_ECDSA_KEY); |
254 |
| - |
255 |
| - final EthTxSigs sigs = EthTxSigs.extractSignatures(signedTx); |
256 |
| - |
257 |
| - Assertions.assertArrayEquals(TRUFFLE0_ADDRESS, sigs.address()); |
258 |
| - Assertions.assertArrayEquals(TRUFFLE0_PUBLIC_ECDSA_KEY, sigs.publicKey()); |
259 |
| - } |
260 |
| - |
261 |
| - @Test |
262 |
| - void equalsToStringHashCode() { |
263 |
| - final var tx = new EthTxData( |
264 |
| - null, |
265 |
| - LEGACY_ETHEREUM, |
266 |
| - CHAINID_TESTNET, |
267 |
| - 1, |
268 |
| - TINYBARS_57_IN_WEIBARS, |
269 |
| - TINYBARS_2_IN_WEIBARS, |
270 |
| - TINYBARS_57_IN_WEIBARS, |
271 |
| - 1_000_000L, |
272 |
| - TRUFFLE1_ADDRESS, |
273 |
| - BigInteger.ZERO, |
274 |
| - ZERO_BYTES, |
275 |
| - ZERO_BYTES, |
276 |
| - 1, |
277 |
| - new byte[0], |
278 |
| - new byte[0], |
279 |
| - new byte[0]); |
280 |
| - |
281 |
| - final EthTxData signedTx = EthTxSigs.signMessage(tx, TRUFFLE0_PRIVATE_ECDSA_KEY); |
282 |
| - final EthTxData signedTxAgain = EthTxSigs.signMessage(tx, TRUFFLE0_PRIVATE_ECDSA_KEY); |
283 |
| - final EthTxData signedTx1 = EthTxSigs.signMessage(tx, TRUFFLE1_PRIVATE_ECDSA_KEY); |
284 |
| - |
285 |
| - final EthTxSigs sigs = EthTxSigs.extractSignatures(signedTx); |
286 |
| - final EthTxSigs sigsAgain = EthTxSigs.extractSignatures(signedTxAgain); |
287 |
| - final EthTxSigs sigs1 = EthTxSigs.extractSignatures(signedTx1); |
288 |
| - |
289 |
| - assertEquals(sigs.toString(), sigsAgain.toString()); |
290 |
| - assertNotEquals(sigs.toString(), sigs1.toString()); |
291 |
| - |
292 |
| - assertDoesNotThrow(sigs::hashCode); |
293 |
| - assertDoesNotThrow(sigsAgain::hashCode); |
294 |
| - assertDoesNotThrow(sigs1::hashCode); |
295 |
| - |
296 |
| - assertEquals(sigs, sigsAgain); |
297 |
| - assertNotEquals(sigs, sigs1); |
298 |
| - } |
299 |
| - |
300 | 94 | @Test
|
301 | 95 | void badSignatureVerification() {
|
302 | 96 | final byte[] allFs = new byte[32];
|
|
0 commit comments