|
|
|
@ -43,6 +43,9 @@ public class TransactionSSZEncodingTest { |
|
|
|
|
private static final String BLOB_TRANSACTIONS_TEST_VECTORS_JSON = |
|
|
|
|
"org/hyperledger/besu/ethereum/core/encoding/blob_transactions_test_vectors.json"; |
|
|
|
|
|
|
|
|
|
private static final String BLOB_TRANSACTIONS_WITHOUT_BLOBS_TEST_VECTORS_JSON = |
|
|
|
|
"org/hyperledger/besu/ethereum/core/encoding/blob_transactions_without_blobs_test_vectors.json"; |
|
|
|
|
|
|
|
|
|
private static Collection<Object[]> blobTransactionsTestVectors() throws IOException { |
|
|
|
|
|
|
|
|
|
ClassLoader classLoader = TransactionSSZEncodingTest.class.getClassLoader(); |
|
|
|
@ -63,6 +66,29 @@ public class TransactionSSZEncodingTest { |
|
|
|
|
.collect(ArrayList::new, ArrayList::add, ArrayList::addAll); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static Collection<Object[]> blobTransactionsTestVectorsWithoutBlobs() throws IOException { |
|
|
|
|
|
|
|
|
|
ClassLoader classLoader = TransactionSSZEncodingTest.class.getClassLoader(); |
|
|
|
|
InputStream inputStream = |
|
|
|
|
classLoader.getResourceAsStream(BLOB_TRANSACTIONS_WITHOUT_BLOBS_TEST_VECTORS_JSON); |
|
|
|
|
JsonParser parser = new JsonFactory().createParser(inputStream); |
|
|
|
|
ObjectMapper mapper = |
|
|
|
|
JsonMapper.builder() |
|
|
|
|
.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true) |
|
|
|
|
.build(); |
|
|
|
|
List<ModelWithoutBlobs> models = mapper.readValue(parser, new TypeReference<>() {}); |
|
|
|
|
|
|
|
|
|
return models.stream() |
|
|
|
|
.map( |
|
|
|
|
model -> |
|
|
|
|
new Object[] { |
|
|
|
|
generateNameWithoutblobs(model.getInput()), |
|
|
|
|
model.getInput(), |
|
|
|
|
model.getRawEncodedTransaction() |
|
|
|
|
}) |
|
|
|
|
.collect(ArrayList::new, ArrayList::add, ArrayList::addAll); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static String generateName(final Input input) { |
|
|
|
|
return " To: " |
|
|
|
|
+ input.getTo() |
|
|
|
@ -76,6 +102,10 @@ public class TransactionSSZEncodingTest { |
|
|
|
|
+ input.getNonce(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static String generateNameWithoutblobs(final InputWithoutBlobs input) { |
|
|
|
|
return " chainId: " + input.getChainId(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ParameterizedTest(name = "[{index}] {0}") |
|
|
|
|
@MethodSource("blobTransactionsTestVectors") |
|
|
|
|
void shouldDecodeSSZTransactions( |
|
|
|
@ -92,6 +122,20 @@ public class TransactionSSZEncodingTest { |
|
|
|
|
assertThat(encodedBytes.toHexString()).isEqualTo(rawTransaction); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ParameterizedTest(name = "[{index}] {0}") |
|
|
|
|
@MethodSource("blobTransactionsTestVectorsWithoutBlobs") |
|
|
|
|
void shouldDecodeSSZTransactionsWithoutBlobs( |
|
|
|
|
final String name, final InputWithoutBlobs input, final String rawTransaction) { |
|
|
|
|
final Bytes bytes = Bytes.fromHexString(rawTransaction); |
|
|
|
|
final Transaction transaction = TransactionDecoder.decodeOpaqueBytes(bytes); |
|
|
|
|
|
|
|
|
|
assertThat(transaction).isNotNull(); |
|
|
|
|
assertThat(transaction.getPayload()).isNotNull(); |
|
|
|
|
final Bytes encodedBytes = TransactionEncoder.encodeOpaqueBytes(transaction); |
|
|
|
|
assertThat(encodedBytes).isNotNull(); |
|
|
|
|
assertThat(encodedBytes.toHexString()).isEqualTo(rawTransaction); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static class Model { |
|
|
|
|
private Input input; |
|
|
|
|
private String rawEncodedTransaction; |
|
|
|
@ -113,6 +157,27 @@ public class TransactionSSZEncodingTest { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static class ModelWithoutBlobs { |
|
|
|
|
private InputWithoutBlobs input; |
|
|
|
|
private String rawEncodedTransaction; |
|
|
|
|
|
|
|
|
|
public InputWithoutBlobs getInput() { |
|
|
|
|
return input; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setInput(final InputWithoutBlobs input) { |
|
|
|
|
this.input = input; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public String getRawEncodedTransaction() { |
|
|
|
|
return rawEncodedTransaction; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setRawEncodedTransaction(final String rawEncodedTransaction) { |
|
|
|
|
this.rawEncodedTransaction = rawEncodedTransaction; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static class Input { |
|
|
|
|
String privateKey; |
|
|
|
|
String to; |
|
|
|
@ -196,4 +261,16 @@ public class TransactionSSZEncodingTest { |
|
|
|
|
this.data = data; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static class InputWithoutBlobs { |
|
|
|
|
String chainId; |
|
|
|
|
|
|
|
|
|
public String getChainId() { |
|
|
|
|
return chainId; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setChainId(final String chainId) { |
|
|
|
|
this.chainId = chainId; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|