From 4c5c61e7641687a5a8d61d5e34d55db0a28eb6ea Mon Sep 17 00:00:00 2001 From: huanghaiquan Date: Tue, 29 Oct 2019 00:39:40 +0800 Subject: [PATCH] Fixed errors of test cases; --- .../ledger/core/ContractInvokingTest.java | 19 ++++++++++--------- .../java/com/jd/blockchain/utils/Dataset.java | 5 +++-- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/ContractInvokingTest.java b/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/ContractInvokingTest.java index 14e29d65..de1d224f 100644 --- a/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/ContractInvokingTest.java +++ b/source/ledger/ledger-core/src/test/java/test/com/jd/blockchain/ledger/core/ContractInvokingTest.java @@ -307,8 +307,8 @@ public class ContractInvokingTest { 0); assertEquals(0, kv1.getVersion()); assertEquals(0, kv2.getVersion()); - assertEquals("V1-0", kv1.getValue()); - assertEquals("V2-0", kv2.getValue()); + assertEquals("V1-0", kv1.getValue().stringValue()); + assertEquals("V2-0", kv2.getValue().stringValue()); // 构建基于接口调用合约的交易请求,用于测试合约调用; buildBlock(ledgerRepo, ledgerManager, opReg, new TxDefinitor() { @@ -326,8 +326,8 @@ public class ContractInvokingTest { kv2 = ledgerRepo.getDataAccountSet().getAccount(kpDataAccount.getAddress()).getDataset().getDataEntry("K2", 1); assertEquals(1, kv1.getVersion()); assertEquals(1, kv2.getVersion()); - assertEquals("V1-1", kv1.getValue()); - assertEquals("V2-1", kv2.getValue()); + assertEquals("V1-1", kv1.getValue().stringValue()); + assertEquals("V2-1", kv2.getValue().stringValue()); // 构建基于接口调用合约的交易请求,用于测试合约调用; buildBlock(ledgerRepo, ledgerManager, opReg, new TxDefinitor() { @@ -337,16 +337,17 @@ public class ContractInvokingTest { contractProxy.testRollbackWhileVersionConfliction(kpDataAccount.getAddress().toBase58(), "K1", "V1-2", 1); contractProxy.testRollbackWhileVersionConfliction(kpDataAccount.getAddress().toBase58(), "K2", "V2-2", - 0); + 0);//预期会回滚; } }); - // 预期数据都能够正常写入; + // 预期数据回滚,账本没有发生变更; kv1 = ledgerRepo.getDataAccountSet().getAccount(kpDataAccount.getAddress()).getDataset().getDataEntry("K1", 1); assertEquals(1, kv1.getVersion()); - assertEquals("V1-1", kv1.getValue()); + assertEquals("V1-1", kv1.getValue().stringValue()); kv1 = ledgerRepo.getDataAccountSet().getAccount(kpDataAccount.getAddress()).getDataset().getDataEntry("K1", 2); - assertEquals(-1, kv1.getVersion()); - assertEquals(null, kv1.getValue()); + assertNull(kv1); + kv2 = ledgerRepo.getDataAccountSet().getAccount(kpDataAccount.getAddress()).getDataset().getDataEntry("K2", 1); + assertEquals(1, kv2.getVersion()); } diff --git a/source/utils/utils-common/src/main/java/com/jd/blockchain/utils/Dataset.java b/source/utils/utils-common/src/main/java/com/jd/blockchain/utils/Dataset.java index 5cd2f2f3..2a82bd19 100644 --- a/source/utils/utils-common/src/main/java/com/jd/blockchain/utils/Dataset.java +++ b/source/utils/utils-common/src/main/java/com/jd/blockchain/utils/Dataset.java @@ -68,7 +68,7 @@ public interface Dataset { long getVersion(K key); /** - * Return data entry + * Return the data entry with the specified key; * * @param key * @return Null if the key doesn't exist! @@ -76,10 +76,11 @@ public interface Dataset { DataEntry getDataEntry(K key); /** + * Return the data entry with the specified key and version; * * @param key * @param version - * @return + * @return Null if the key doesn't exist! */ DataEntry getDataEntry(K key, long version);