Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package org.fisco.bcos.sdk.v3.client.exceptions;

import org.junit.Assert;
import org.junit.Test;

public class ClientExceptionTest {

@Test
public void testConstructorWithErrorCodeAndMessage() {
int errorCode = 100;
String errorMessage = "Test Error";
String message = "Full message";

ClientException exception = new ClientException(errorCode, errorMessage, message);

Assert.assertEquals(errorCode, exception.getErrorCode());
Assert.assertEquals(errorMessage, exception.getErrorMessage());
Assert.assertEquals(message, exception.getMessage());
}

@Test
public void testConstructorWithErrorCodeMessageAndCause() {
int errorCode = 200;
String errorMessage = "Test Error";
String message = "Full message";
Throwable cause = new RuntimeException("Cause");

ClientException exception = new ClientException(errorCode, errorMessage, message, cause);

Assert.assertEquals(errorCode, exception.getErrorCode());
Assert.assertEquals(errorMessage, exception.getErrorMessage());
Assert.assertEquals(message, exception.getMessage());
Assert.assertEquals(cause, exception.getCause());
}

@Test
public void testConstructorWithMessage() {
String message = "Simple message";

ClientException exception = new ClientException(message);

Assert.assertEquals(message, exception.getMessage());
}

@Test
public void testConstructorWithMessageAndCause() {
String message = "Message with cause";
Throwable cause = new RuntimeException("Root cause");

ClientException exception = new ClientException(message, cause);

Assert.assertEquals(message, exception.getMessage());
Assert.assertEquals(cause, exception.getCause());
}

@Test
public void testSetErrorCode() {
ClientException exception = new ClientException("Test");
exception.setErrorCode(300);

Assert.assertEquals(300, exception.getErrorCode());
}

@Test
public void testSetErrorMessage() {
ClientException exception = new ClientException("Test");
exception.setErrorMessage("New error message");

Assert.assertEquals("New error message", exception.getErrorMessage());
}

@Test
public void testToString() {
int errorCode = 400;
String errorMessage = "Error Message";
String message = "Full Message";

ClientException exception = new ClientException(errorCode, errorMessage, message);

String result = exception.toString();
Assert.assertNotNull(result);
Assert.assertTrue(result.contains(String.valueOf(errorCode)));
Assert.assertTrue(result.contains(errorMessage));
Assert.assertTrue(result.contains(message));
}

@Test
public void testEquals() {
ClientException exception1 = new ClientException(100, "Error", "Message");
ClientException exception2 = new ClientException(100, "Error", "Message");
ClientException exception3 = new ClientException(200, "Error", "Message");

Assert.assertEquals(exception1, exception2);
Assert.assertNotEquals(exception1, exception3);
Assert.assertEquals(exception1, exception1);
Assert.assertNotEquals(exception1, null);
Assert.assertNotEquals(exception1, "String");
}

@Test
public void testHashCode() {
ClientException exception1 = new ClientException(100, "Error", "Message");
ClientException exception2 = new ClientException(100, "Error", "Message");

Assert.assertEquals(exception1.hashCode(), exception2.hashCode());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package org.fisco.bcos.sdk.v3.client.protocol.model;

import org.junit.Assert;
import org.junit.Test;

public class GroupStatusTest {

@Test
public void testGettersAndSetters() {
GroupStatus groupStatus = new GroupStatus();

groupStatus.setCode("200");
groupStatus.setMessage("Success");
groupStatus.setStatus("running");

Assert.assertEquals("200", groupStatus.getCode());
Assert.assertEquals("Success", groupStatus.getMessage());
Assert.assertEquals("running", groupStatus.getStatus());
}

@Test
public void testEquals() {
GroupStatus status1 = new GroupStatus();
status1.setCode("200");
status1.setMessage("Success");
status1.setStatus("running");

GroupStatus status2 = new GroupStatus();
status2.setCode("200");
status2.setMessage("Success");
status2.setStatus("running");

GroupStatus status3 = new GroupStatus();
status3.setCode("404");
status3.setMessage("Not Found");
status3.setStatus("stopped");

Assert.assertEquals(status1, status2);
Assert.assertNotEquals(status1, status3);
Assert.assertEquals(status1, status1);
Assert.assertNotEquals(status1, null);
Assert.assertNotEquals(status1, "String");
}

@Test
public void testHashCode() {
GroupStatus status1 = new GroupStatus();
status1.setCode("200");
status1.setMessage("Success");
status1.setStatus("running");

GroupStatus status2 = new GroupStatus();
status2.setCode("200");
status2.setMessage("Success");
status2.setStatus("running");

Assert.assertEquals(status1.hashCode(), status2.hashCode());
}

@Test
public void testToString() {
GroupStatus groupStatus = new GroupStatus();
groupStatus.setCode("200");
groupStatus.setMessage("Success");
groupStatus.setStatus("running");

String result = groupStatus.toString();
Assert.assertNotNull(result);
Assert.assertTrue(result.contains("200"));
Assert.assertTrue(result.contains("Success"));
Assert.assertTrue(result.contains("running"));
}

@Test
public void testWithNullValues() {
GroupStatus groupStatus = new GroupStatus();

Assert.assertNull(groupStatus.getCode());
Assert.assertNull(groupStatus.getMessage());
Assert.assertNull(groupStatus.getStatus());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.fisco.bcos.sdk.v3.client.protocol.model;

import org.junit.Assert;
import org.junit.Test;

public class TransactionAttributeTest {

@Test
public void testEVM_ABI_CODEC() {
Assert.assertEquals(0x1, TransactionAttribute.EVM_ABI_CODEC);
}

@Test
public void testLIQUID_SCALE_CODEC() {
Assert.assertEquals(0x2, TransactionAttribute.LIQUID_SCALE_CODEC);
}

@Test
public void testDAG() {
Assert.assertEquals(0x4, TransactionAttribute.DAG);
}

@Test
public void testLIQUID_CREATE() {
Assert.assertEquals(0x8, TransactionAttribute.LIQUID_CREATE);
}

@Test
public void testAttributeValues() {
// Verify that the constants are unique
Assert.assertNotEquals(TransactionAttribute.EVM_ABI_CODEC, TransactionAttribute.LIQUID_SCALE_CODEC);
Assert.assertNotEquals(TransactionAttribute.EVM_ABI_CODEC, TransactionAttribute.DAG);
Assert.assertNotEquals(TransactionAttribute.EVM_ABI_CODEC, TransactionAttribute.LIQUID_CREATE);
Assert.assertNotEquals(TransactionAttribute.LIQUID_SCALE_CODEC, TransactionAttribute.DAG);
Assert.assertNotEquals(TransactionAttribute.LIQUID_SCALE_CODEC, TransactionAttribute.LIQUID_CREATE);
Assert.assertNotEquals(TransactionAttribute.DAG, TransactionAttribute.LIQUID_CREATE);
}

@Test
public void testAttributesBitFlags() {
// Test that attributes can be used as bit flags
int combined = TransactionAttribute.EVM_ABI_CODEC | TransactionAttribute.DAG;
Assert.assertEquals(0x5, combined);

Assert.assertTrue((combined & TransactionAttribute.EVM_ABI_CODEC) != 0);
Assert.assertTrue((combined & TransactionAttribute.DAG) != 0);
Assert.assertFalse((combined & TransactionAttribute.LIQUID_SCALE_CODEC) != 0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.fisco.bcos.sdk.v3.client.protocol.request;

import org.junit.Assert;
import org.junit.Test;

public class DefaultBlockParameterNameTest {

@Test
public void testEarliestValue() {
Assert.assertEquals("earliest", DefaultBlockParameterName.EARLIEST.getValue());
}

@Test
public void testLatestValue() {
Assert.assertEquals("latest", DefaultBlockParameterName.LATEST.getValue());
}

@Test
public void testIsLatest() {
Assert.assertTrue(DefaultBlockParameterName.LATEST.isLatest());
Assert.assertFalse(DefaultBlockParameterName.EARLIEST.isLatest());
}

@Test
public void testIsEarliest() {
Assert.assertTrue(DefaultBlockParameterName.EARLIEST.isEarliest());
Assert.assertFalse(DefaultBlockParameterName.LATEST.isEarliest());
}

@Test
public void testFromStringWithEarliest() {
DefaultBlockParameterName result = DefaultBlockParameterName.fromString("earliest");
Assert.assertEquals(DefaultBlockParameterName.EARLIEST, result);
}

@Test
public void testFromStringWithLatest() {
DefaultBlockParameterName result = DefaultBlockParameterName.fromString("latest");
Assert.assertEquals(DefaultBlockParameterName.LATEST, result);
}

@Test
public void testFromStringCaseInsensitive() {
DefaultBlockParameterName result1 = DefaultBlockParameterName.fromString("EARLIEST");
Assert.assertEquals(DefaultBlockParameterName.EARLIEST, result1);

DefaultBlockParameterName result2 = DefaultBlockParameterName.fromString("Latest");
Assert.assertEquals(DefaultBlockParameterName.LATEST, result2);
}

@Test(expected = IllegalArgumentException.class)
public void testFromStringWithInvalidValue() {
DefaultBlockParameterName.fromString("invalid");
}

@Test(expected = NullPointerException.class)
public void testFromStringWithNull() {
DefaultBlockParameterName.fromString(null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.fisco.bcos.sdk.v3.client.protocol.request;

import org.junit.Assert;
import org.junit.Test;
import java.math.BigInteger;

public class DefaultBlockParameterNumberTest {

@Test
public void testConstructorWithBigInteger() {
BigInteger blockNumber = BigInteger.valueOf(100);
DefaultBlockParameterNumber parameter = new DefaultBlockParameterNumber(blockNumber);

Assert.assertEquals(blockNumber, parameter.getBlockNumber());
}

@Test
public void testConstructorWithLong() {
long blockNumber = 200L;
DefaultBlockParameterNumber parameter = new DefaultBlockParameterNumber(blockNumber);

Assert.assertEquals(BigInteger.valueOf(blockNumber), parameter.getBlockNumber());
}

@Test
public void testGetValueReturnsHexString() {
DefaultBlockParameterNumber parameter = new DefaultBlockParameterNumber(BigInteger.valueOf(100));

String value = parameter.getValue();
Assert.assertNotNull(value);
Assert.assertTrue(value.startsWith("0x"));
}

@Test
public void testIsLatest() {
DefaultBlockParameterNumber parameter = new DefaultBlockParameterNumber(BigInteger.valueOf(100));

Assert.assertFalse(parameter.isLatest());
}

@Test
public void testIsEarliest() {
DefaultBlockParameterNumber parameter = new DefaultBlockParameterNumber(BigInteger.valueOf(100));

Assert.assertFalse(parameter.isEarliest());
}

@Test
public void testWithZeroBlockNumber() {
DefaultBlockParameterNumber parameter = new DefaultBlockParameterNumber(BigInteger.ZERO);

Assert.assertEquals(BigInteger.ZERO, parameter.getBlockNumber());
Assert.assertEquals("0x0", parameter.getValue());
}

@Test
public void testWithLargeBlockNumber() {
BigInteger largeNumber = new BigInteger("999999999999999999");
DefaultBlockParameterNumber parameter = new DefaultBlockParameterNumber(largeNumber);

Assert.assertEquals(largeNumber, parameter.getBlockNumber());
}
}
Loading