Skip to content

Commit

Permalink
test: add shouldBytesNoSetters tests
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Ivanov <[email protected]>
  • Loading branch information
0xivanov committed Dec 2, 2024
1 parent dff3bef commit aa6f575
Show file tree
Hide file tree
Showing 51 changed files with 358 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ void propertiesTest() {
assertThat(tx.getTokenNftApprovals()).isNotEmpty();
}

@Test
void shouldBytesNoSetters() throws Exception {
var tx = new AccountAllowanceApproveTransaction();
var tx2 = AccountAllowanceApproveTransaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}


@Test
void fromScheduledTransaction() {
var transactionBody = SchedulableTransactionBody.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,14 @@ void shouldSerialize() {
@Test
void shouldBytes() throws Exception {
var tx = spawnTestTransaction();
var tx2 = AccountAllowanceApproveTransaction.fromBytes(tx.toBytes());
var tx2 = AccountAllowanceDeleteTransaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

@Test
void shouldBytesNoSetters() throws Exception {
var tx = new AccountAllowanceDeleteTransaction();
var tx2 = Transaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ void shouldBytes2() throws Exception {
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

@Test
void shouldBytesNoSetters() throws Exception {
var tx = new AccountCreateTransaction();
var tx2 = Transaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}


@Test
void propertiesTest() {
var tx = spawnTestTransaction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ void shouldBytes() throws Exception {
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

@Test
void shouldBytesNoSetters() throws Exception {
var tx = new AccountDeleteTransaction();
var tx2 = Transaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

@Test
void fromScheduledTransaction() {
var transactionBody = SchedulableTransactionBody.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ void shouldBytes() throws Exception {
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

@Test
void shouldBytesNoSetters() throws Exception {
var tx = new AccountUpdateTransaction();
var tx2 = Transaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

@Test
void shouldSerialize2() {
SnapshotMatcher.expect(spawnTestTransaction2().toString()).toMatchSnapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ void shouldSerialize2() {
).toMatchSnapshot();
}

@Test
void shouldBytesNoSetters() throws Exception {
var tx = new ContractCreateTransaction();
var tx2 = Transaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

private ContractCreateTransaction spawnTestTransaction() {
return new ContractCreateTransaction()
.setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ void shouldBytes() throws Exception {
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

@Test
void shouldBytesNoSetters() throws Exception {
var tx = new ContractDeleteTransaction();
var tx2 = Transaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

@Test
void fromScheduledTransaction() {
var transactionBody = SchedulableTransactionBody.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ void shouldSerialize() {
).toMatchSnapshot();
}

@Test
void shouldBytesNoSetters() throws Exception {
var tx = new ContractExecuteTransaction();
var tx2 = Transaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

private ContractExecuteTransaction spawnTestTransaction() {
return new ContractExecuteTransaction()
.setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ void shouldSerialize2() {
).toMatchSnapshot();
}

@Test
void shouldBytesNoSetters() throws Exception {
var tx = new ContractUpdateTransaction();
var tx2 = Transaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

private ContractUpdateTransaction spawnTestTransaction() {
return new ContractUpdateTransaction()
.setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ void shouldSerialize() {
).toMatchSnapshot();
}

@Test
void shouldBytesNoSetters() throws Exception {
var tx = new TransferTransaction();
var tx2 = Transaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

private TransferTransaction spawnTestTransaction() {
return new TransferTransaction()
.setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ EthereumTransaction spawnTestTransaction() {
.sign(unusedPrivateKey);
}

@Test
void shouldBytesNoSetters() throws Exception {
var tx = new EthereumTransaction();
var tx2 = Transaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

@Test
void shouldSerialize() {
SnapshotMatcher.expect(spawnTestTransaction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ private FileAppendTransaction spawnTestTransaction(List<AccountId> accountIds) {
.sign(unusedPrivateKey);
}

@Test
void shouldBytesNoSetters() throws Exception {
var tx = new FileAppendTransaction();
var tx2 = Transaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

@Test
void shouldSerializeBigContents() {
var nodeAccountIds = new ArrayList<AccountId>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ void shouldSerialize() {
).toMatchSnapshot();
}

@Test
void shouldBytesNoSetters() throws Exception {
var tx = new FileCreateTransaction();
var tx2 = Transaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

private FileCreateTransaction spawnTestTransaction() {
return new FileCreateTransaction()
.setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ void shouldSerialize() {
).toMatchSnapshot();
}

@Test
void shouldBytesNoSetters() throws Exception {
var tx = new FileDeleteTransaction();
var tx2 = Transaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

private FileDeleteTransaction spawnTestTransaction() {
return new FileDeleteTransaction()
.setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ void shouldBytes() throws Exception {
assertThat(tx2.toString()).isEqualTo(tx.toString());
}


@Test
void shouldBytesNoSetters() throws Exception {
var tx = new FileUpdateTransaction();
var tx2 = Transaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}


@Test
void fromScheduledTransaction() {
var transactionBody = SchedulableTransactionBody.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ void shouldBytes() throws Exception {
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

@Test
void shouldBytesNoSetters() throws Exception {
var tx = new FreezeTransaction();
var tx2 = Transaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

@Test
void fromScheduledTransaction() {
var transactionBody = SchedulableTransactionBody.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ private LiveHashAddTransaction spawnTestTransaction() {
.sign(privateKey);
}

@Test
void shouldBytesNoSetters() throws Exception {
var tx = new LiveHashAddTransaction();
var tx2 = Transaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

@Test
void shouldBytes() throws Exception {
var tx = spawnTestTransaction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ private LiveHashDeleteTransaction spawnTestTransaction() {
@Test
void shouldBytes() throws Exception {
var tx = spawnTestTransaction();
var tx2 = LiveHashAddTransaction.fromBytes(tx.toBytes());
var tx2 = LiveHashDeleteTransaction.fromBytes(tx.toBytes());
assertThat(tx2).hasToString(tx.toString());
}

@Test
void shouldBytesNoSetters() throws Exception {
var tx = new LiveHashDeleteTransaction();
var tx2 = Transaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ void shouldBytes() throws Exception {
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

@Test
void shouldBytesNoSetters() throws Exception {
var tx = new TopicMessageSubmitTransaction();
var tx2 = Transaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

@Test
void shouldSerialize() {
SnapshotMatcher.expect(spawnTestTransaction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,12 @@ void fromScheduledTransaction() {
assertThat(tx).isInstanceOf(NodeCreateTransaction.class);
}


@Test
void testSerializeDeserialize() throws Exception {
var tx = new NodeCreateTransaction().setDescription(TEST_DESCRIPTION);
var tx2 = new NodeCreateTransaction().setDescription(TEST_DESCRIPTION);
var tx2Bytes = tx2.toBytes();
NodeCreateTransaction deserializedTx2 = (NodeCreateTransaction) Transaction.fromBytes(tx2Bytes);
assertThat(tx.getGossipCaCertificate()).isEqualTo(deserializedTx2.getGossipCaCertificate());
assertThat(tx.getGrpcCertificateHash()).isEqualTo(deserializedTx2.getGrpcCertificateHash());
void shouldBytesNoSetters() throws Exception {
var tx = new NodeCreateTransaction();
var tx2 = Transaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

@Test
Expand All @@ -142,7 +140,6 @@ void testSetNull() {
.setAdminKey(null);
}


@Test
void constructNodeCreateTransactionFromTransactionBodyProtobuf() {
var transactionBodyBuilder = NodeCreateTransactionBody.newBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ void shouldBytes() throws Exception {
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

@Test
void shouldBytesNoSetters() throws Exception {
var tx = new NodeDeleteTransaction();
var tx2 = Transaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

@Test
void fromScheduledTransaction() {
var transactionBody = SchedulableTransactionBody.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,10 @@ void shouldBytes() throws Exception {
}

@Test
void testNullOptionalValues() throws Exception {
void shouldBytesNoSetters() throws Exception {
var tx = new NodeUpdateTransaction();
var tx2Bytes = tx.toBytes();
NodeUpdateTransaction deserializedTx = (NodeUpdateTransaction) Transaction.fromBytes(tx2Bytes);
assertThat(deserializedTx.getGossipCaCertificate()).isNull();
assertThat(deserializedTx.getGrpcCertificateHash()).isNull();
assertThat(deserializedTx.getDescription()).isNull();
var tx2 = Transaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,11 @@ void shouldBytes() throws Exception {
var tx2 = ScheduleCreateTransaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

@Test
void shouldBytesNoSetters() throws Exception {
var tx = new ScheduleCreateTransaction();
var tx2 = Transaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ void shouldBytes() throws Exception {
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

@Test
void shouldBytesNoSetters() throws Exception {
var tx = new ScheduleDeleteTransaction();
var tx2 = Transaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

@Test
void fromScheduledTransaction() {
var transactionBody = SchedulableTransactionBody.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ void shouldSerialize() {
).toMatchSnapshot();
}

@Test
void shouldBytesNoSetters() throws Exception {
var tx = new ScheduleSignTransaction();
var tx2 = Transaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

private ScheduleSignTransaction spawnTestTransaction() {
return new ScheduleSignTransaction()
.setNodeAccountIds(Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ void shouldSerializeContract() {
SnapshotMatcher.expect(spawnTestTransactionContract().toString()).toMatchSnapshot();
}

@Test
void shouldBytesNoSetters() throws Exception {
var tx = new SystemDeleteTransaction();
var tx2 = Transaction.fromBytes(tx.toBytes());
assertThat(tx2.toString()).isEqualTo(tx.toString());
}

private SystemDeleteTransaction spawnTestTransactionContract() {
return new SystemDeleteTransaction().setNodeAccountIds(
Arrays.asList(AccountId.fromString("0.0.5005"), AccountId.fromString("0.0.5006")))
Expand Down
Loading

0 comments on commit aa6f575

Please sign in to comment.