Skip to content

Commit

Permalink
feat(jsonrpc): add test cases for jsonrpc finalized
Browse files Browse the repository at this point in the history
  • Loading branch information
waynercheung committed Jan 13, 2025
1 parent 6a32bb1 commit eb8e59a
Show file tree
Hide file tree
Showing 3 changed files with 406 additions and 169 deletions.
23 changes: 17 additions & 6 deletions framework/src/test/java/org/tron/core/WalletTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public class WalletTest extends BaseTest {
private static boolean init;

static {
Args.setParam(new String[]{"-d", dbPath()}, Constant.TEST_CONF);
Args.setParam(new String[] {"-d", dbPath()}, Constant.TEST_CONF);
OWNER_ADDRESS = Wallet.getAddressPreFixString() + "548794500882809695a8a687866e76d4271a1abc";
RECEIVER_ADDRESS = Wallet.getAddressPreFixString() + "abd4b9367799eaa3197fecb144eb71de1e049150";
}
Expand All @@ -152,7 +152,8 @@ public void before() {
}
initTransaction();
initBlock();
chainBaseManager.getDynamicPropertiesStore().saveLatestBlockHeaderNumber(5);
chainBaseManager.getDynamicPropertiesStore().saveLatestBlockHeaderNumber(BLOCK_NUM_FIVE);
chainBaseManager.getDynamicPropertiesStore().saveLatestSolidifiedBlockNum(BLOCK_NUM_TWO);
chainBaseManager.getDelegatedResourceStore().reset();
init = true;
}
Expand All @@ -166,6 +167,7 @@ private void initTransaction() {
TRANSACTION_TIMESTAMP_ONE, BLOCK_NUM_ONE);
addTransactionToStore(transaction1);

// solidified
transaction2 = getBuildTransaction(
getBuildTransferContract(ACCOUNT_ADDRESS_TWO, ACCOUNT_ADDRESS_THREE),
TRANSACTION_TIMESTAMP_TWO, BLOCK_NUM_TWO);
Expand Down Expand Up @@ -284,6 +286,7 @@ private void initBlock() {

private void addBlockToStore(Block block) {
BlockCapsule blockCapsule = new BlockCapsule(block);
chainBaseManager.getBlockIndexStore().put(blockCapsule.getBlockId());
chainBaseManager.getBlockStore().put(blockCapsule.getBlockId().getBytes(), blockCapsule);
}

Expand Down Expand Up @@ -1169,19 +1172,19 @@ public void testListNodes() {
* delegate_balance = 1000_000L; => 277
* delegate_balance = 1000_000_000L; => 279
* delegate_balance = 1000_000_000_000L => 280
*
* <p>
* We initialize account information as follows
* account balance = 1000_000_000_000L
* account frozen_balance = 1000_000_000L
*
* <p>
* then estimateConsumeBandWidthSize cost 279
*
* <p>
* so we have following result:
* TransactionUtil.estimateConsumeBandWidthSize(
* dynamicStore,ownerCapsule.getBalance()) ===> false
* TransactionUtil.estimateConsumeBandWidthSize(
* dynamicStore,ownerCapsule.getFrozenV2BalanceForBandwidth()) ===> true
*
* <p>
* This test case is used to verify the above conclusions
*/
@Test
Expand All @@ -1206,5 +1209,13 @@ public void testGetCanDelegatedMaxSizeBandWidth123() {
chainBaseManager.getDynamicPropertiesStore().saveMaxDelegateLockPeriod(DELEGATE_PERIOD / 3000);
}

@Test
public void testGetSolidBlock() {
long blkNum = wallet.getSolidBlockNum();
Assert.assertEquals(BLOCK_NUM_TWO, blkNum);

Block block = wallet.getSolidBlock();
assertEquals(block2, block);
}
}

104 changes: 1 addition & 103 deletions framework/src/test/java/org/tron/core/jsonrpc/JsonRpcTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ public void testLogFilter() {
} catch (JsonRpcInvalidParamsException e) {
Assert.fail();
}

try {
new LogFilter(new FilterRequest(null, null, null, new String[] {"0x0"}, null));
} catch (JsonRpcInvalidParamsException e) {
Expand Down Expand Up @@ -240,109 +241,6 @@ public void testLogFilter() {
}
}

/**
* test fromBlock and toBlock parameters
*/
@Test
public void testLogFilterWrapper() {

// fromBlock and toBlock are both empty
try {
LogFilterWrapper logFilterWrapper =
new LogFilterWrapper(new FilterRequest(null, null, null, null, null), 100, null);
Assert.assertEquals(logFilterWrapper.getFromBlock(), 100);
Assert.assertEquals(logFilterWrapper.getToBlock(), Long.MAX_VALUE);
} catch (JsonRpcInvalidParamsException e) {
Assert.fail();
}

// fromBlock is not empty and smaller than currentMaxBlockNum, toBlock is empty
try {
LogFilterWrapper logFilterWrapper =
new LogFilterWrapper(new FilterRequest("0x14", null, null, null, null), 100, null);
Assert.assertEquals(logFilterWrapper.getFromBlock(), 20);
Assert.assertEquals(logFilterWrapper.getToBlock(), Long.MAX_VALUE);
} catch (JsonRpcInvalidParamsException e) {
Assert.fail();
}

// fromBlock is not empty and bigger than currentMaxBlockNum, toBlock is empty
try {
LogFilterWrapper logFilterWrapper =
new LogFilterWrapper(new FilterRequest("0x78", null, null, null, null), 100, null);
Assert.assertEquals(logFilterWrapper.getFromBlock(), 120);
Assert.assertEquals(logFilterWrapper.getToBlock(), Long.MAX_VALUE);
} catch (JsonRpcInvalidParamsException e) {
Assert.fail();
}

// fromBlock is empty, toBlock is not empty and smaller than currentMaxBlockNum
try {
LogFilterWrapper logFilterWrapper =
new LogFilterWrapper(new FilterRequest(null, "0x14", null, null, null), 100, null);
Assert.assertEquals(logFilterWrapper.getFromBlock(), 20);
Assert.assertEquals(logFilterWrapper.getToBlock(), 20);
} catch (JsonRpcInvalidParamsException e) {
Assert.fail();
}

// fromBlock is empty, toBlock is not empty and bigger than currentMaxBlockNum
try {
LogFilterWrapper logFilterWrapper =
new LogFilterWrapper(new FilterRequest(null, "0x78", null, null, null), 100, null);
Assert.assertEquals(logFilterWrapper.getFromBlock(), 100);
Assert.assertEquals(logFilterWrapper.getToBlock(), 120);
} catch (JsonRpcInvalidParamsException e) {
Assert.fail();
}

// fromBlock is not empty, toBlock is not empty
try {
LogFilterWrapper logFilterWrapper =
new LogFilterWrapper(new FilterRequest("0x14", "0x78", null, null, null), 100, null);
Assert.assertEquals(logFilterWrapper.getFromBlock(), 20);
Assert.assertEquals(logFilterWrapper.getToBlock(), 120);
} catch (JsonRpcInvalidParamsException e) {
Assert.fail();
}
try {
LogFilterWrapper logFilterWrapper =
new LogFilterWrapper(new FilterRequest("0x78", "0x14", null, null, null), 100, null);
} catch (JsonRpcInvalidParamsException e) {
Assert.assertEquals("please verify: fromBlock <= toBlock", e.getMessage());
}

//fromBlock or toBlock is not hex num
try {
LogFilterWrapper logFilterWrapper =
new LogFilterWrapper(new FilterRequest("earliest", null, null, null, null), 100, null);
Assert.assertEquals(logFilterWrapper.getFromBlock(), 0);
Assert.assertEquals(logFilterWrapper.getToBlock(), Long.MAX_VALUE);
} catch (JsonRpcInvalidParamsException e) {
Assert.fail();
}
try {
LogFilterWrapper logFilterWrapper =
new LogFilterWrapper(new FilterRequest("latest", null, null, null, null), 100, null);
Assert.assertEquals(logFilterWrapper.getFromBlock(), 100);
Assert.assertEquals(logFilterWrapper.getToBlock(), Long.MAX_VALUE);
} catch (JsonRpcInvalidParamsException e) {
Assert.fail();
}
try {
LogFilterWrapper logFilterWrapper =
new LogFilterWrapper(new FilterRequest("pending", null, null, null, null), 100, null);
} catch (JsonRpcInvalidParamsException e) {
Assert.assertEquals("TAG pending not supported", e.getMessage());
}
try {
LogFilterWrapper logFilterWrapper =
new LogFilterWrapper(new FilterRequest("test", null, null, null, null), 100, null);
} catch (JsonRpcInvalidParamsException e) {
Assert.assertEquals("Incorrect hex syntax", e.getMessage());
}
}

private int[] getBloomIndex(String s) {
Bloom bloom = Bloom.create(Hash.sha3(ByteArray.fromHexString(s)));
BitSet bs = BitSet.valueOf(bloom.getData());
Expand Down
Loading

0 comments on commit eb8e59a

Please sign in to comment.