diff --git a/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/ContractSample.java b/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/ContractSample.java index 696f7bf5..db6ef26a 100644 --- a/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/ContractSample.java +++ b/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/ContractSample.java @@ -1,6 +1,7 @@ package com.jdchain.samples.sdk; import com.jd.blockchain.crypto.KeyGenUtils; +import com.jd.blockchain.ledger.AccountState; import com.jd.blockchain.ledger.BlockchainIdentity; import com.jd.blockchain.ledger.BlockchainIdentityData; import com.jd.blockchain.ledger.BlockchainKeyGenerator; @@ -15,12 +16,10 @@ import com.jd.blockchain.transaction.ContractEventSendOperationBuilder; import com.jd.blockchain.transaction.ContractReturnValue; import com.jd.blockchain.transaction.GenericValueHolder; import com.jdchain.samples.contract.SampleContract; - -import utils.io.BytesUtils; -import utils.io.FileUtils; - import org.junit.Assert; import org.junit.Test; +import utils.io.BytesUtils; +import utils.io.FileUtils; import java.util.UUID; @@ -140,4 +139,37 @@ public class ContractSample extends SampleBase { } } + /** + * 更新合约状态 + */ + @Test + public void updateContractState() { + // 新建交易 + TransactionTemplate txTemp = blockchainService.newTransaction(ledger); + // 合约状态分为:NORMAL(正常) FREEZE(冻结) REVOKE(销毁) + // 冻结合约 + txTemp.contract("LdeNr7H1CUbqe3kWjwPwiqHcmd86zEQz2VRye").state(AccountState.FREEZE); + // 交易准备 + PreparedTransaction ptx = txTemp.prepare(); + // 提交交易 + TransactionResponse response = ptx.commit(); + Assert.assertTrue(response.isSuccess()); + } + + /** + * 更新合约权限 + */ + @Test + public void updateDPermission() { + // 新建交易 + TransactionTemplate txTemp = blockchainService.newTransaction(ledger); + // 配置合约权限 + // 如下配置表示仅有 ROLE 角色用户才有调用 LdeNr7H1CUbqe3kWjwPwiqHcmd86zEQz2VRye 权限 + txTemp.contract("LdeNr7H1CUbqe3kWjwPwiqHcmd86zEQz2VRye").permission().mode(70).role("ROLE"); + // 交易准备 + PreparedTransaction ptx = txTemp.prepare(); + // 提交交易 + TransactionResponse response = ptx.commit(); + Assert.assertTrue(response.isSuccess()); + } } diff --git a/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/DataAccountSample.java b/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/DataAccountSample.java index 7a0693bf..4b0a3d74 100644 --- a/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/DataAccountSample.java +++ b/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/DataAccountSample.java @@ -5,11 +5,9 @@ import com.jd.blockchain.ledger.BlockchainKeypair; import com.jd.blockchain.ledger.PreparedTransaction; import com.jd.blockchain.ledger.TransactionResponse; import com.jd.blockchain.ledger.TransactionTemplate; - -import utils.Bytes; - import org.junit.Assert; import org.junit.Test; +import utils.Bytes; /** * 数据账户相关操作示例: @@ -81,4 +79,20 @@ public class DataAccountSample extends SampleBase { Assert.assertTrue(response.isSuccess()); } + /** + * 更新数据账户权限 + */ + @Test + public void updateDPermission() { + // 新建交易 + TransactionTemplate txTemp = blockchainService.newTransaction(ledger); + // 配置数据账户权限 + // 如下配置表示仅有 ROLE 角色用户才有写入 LdeNr7H1CUbqe3kWjwPwiqHcmd86zEQz2VRye 权限 + txTemp.dataAccount("LdeNr7H1CUbqe3kWjwPwiqHcmd86zEQz2VRye").permission().mode(70).role("ROLE"); + // 交易准备 + PreparedTransaction ptx = txTemp.prepare(); + // 提交交易 + TransactionResponse response = ptx.commit(); + Assert.assertTrue(response.isSuccess()); + } } diff --git a/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/EventSample.java b/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/EventSample.java index 0fb93d58..8effbf0a 100644 --- a/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/EventSample.java +++ b/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/EventSample.java @@ -8,12 +8,10 @@ import com.jd.blockchain.ledger.PreparedTransaction; import com.jd.blockchain.ledger.SystemEvent; import com.jd.blockchain.ledger.TransactionResponse; import com.jd.blockchain.ledger.TransactionTemplate; - -import utils.Bytes; -import utils.io.BytesUtils; - import org.junit.Assert; import org.junit.Test; +import utils.Bytes; +import utils.io.BytesUtils; import java.util.concurrent.CountDownLatch; @@ -132,4 +130,20 @@ public class EventSample extends SampleBase { Assert.assertTrue(response.isSuccess()); } + /** + * 更新事件账户权限 + */ + @Test + public void updateDPermission() { + // 新建交易 + TransactionTemplate txTemp = blockchainService.newTransaction(ledger); + // 配置事件账户权限 + // 如下配置表示仅有 ROLE 角色用户才有写入 LdeNr7H1CUbqe3kWjwPwiqHcmd86zEQz2VRye 权限 + txTemp.eventAccount("LdeNr7H1CUbqe3kWjwPwiqHcmd86zEQz2VRye").permission().mode(70).role("ROLE"); + // 交易准备 + PreparedTransaction ptx = txTemp.prepare(); + // 提交交易 + TransactionResponse response = ptx.commit(); + Assert.assertTrue(response.isSuccess()); + } } diff --git a/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/UserSample.java b/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/UserSample.java index 1af5d910..d5a6ff79 100644 --- a/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/UserSample.java +++ b/samples/sdk-samples/src/test/java/com/jdchain/samples/sdk/UserSample.java @@ -1,5 +1,6 @@ package com.jdchain.samples.sdk; +import com.jd.blockchain.ledger.AccountState; import com.jd.blockchain.ledger.BlockchainKeyGenerator; import com.jd.blockchain.ledger.BlockchainKeypair; import com.jd.blockchain.ledger.LedgerPermission; @@ -7,11 +8,9 @@ import com.jd.blockchain.ledger.PreparedTransaction; import com.jd.blockchain.ledger.TransactionPermission; import com.jd.blockchain.ledger.TransactionResponse; import com.jd.blockchain.ledger.TransactionTemplate; - -import utils.Bytes; - import org.junit.Assert; import org.junit.Test; +import utils.Bytes; /** * 用户账户相关操作示例: @@ -102,4 +101,20 @@ public class UserSample extends SampleBase { Assert.assertTrue(response.isSuccess()); } + /** + * 更新用户状态 + */ + @Test + public void updateUserState() { + // 新建交易 + TransactionTemplate txTemp = blockchainService.newTransaction(ledger); + // 用户(证书)状态分为:NORMAL(正常) FREEZE(冻结) REVOKE(销毁) + // 冻结用户(证书) + txTemp.user("LdeNr7H1CUbqe3kWjwPwiqHcmd86zEQz2VRye").state(AccountState.FREEZE); + // 交易准备 + PreparedTransaction ptx = txTemp.prepare(); + // 提交交易 + TransactionResponse response = ptx.commit(); + Assert.assertTrue(response.isSuccess()); + } }