Skip to content
Open
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
Expand Up @@ -118,6 +118,62 @@ public void testUpdateBlockchainAnchor() throws IOException {
Assert.assertEquals(PS_ID, blockchainMeta.getPluginServerId());
}

@Test
public void testUpdateBlockchainPreservesPropertiesOnPartialConfig() {

BlockchainMeta blockchainMeta = blockchainManager.getBlockchainMetaByDomain(antChainDotComDomain);
String amAddr = "AM_CONTRACT_TO_KEEP";
String sdpAddr = "SDP_CONTRACT_TO_KEEP";
String ptcAddr = "PTC_CONTRACT_TO_KEEP";
long initBlockHeight = 12345L;

blockchainMeta.getProperties().setAmClientContractAddress(amAddr);
blockchainMeta.getProperties().setSdpMsgContractAddress(sdpAddr);
blockchainMeta.getProperties().setPtcContractAddress(ptcAddr);
blockchainMeta.getProperties().setInitBlockHeight(initBlockHeight);
blockchainMeta.getProperties().setIsDomainRegistered(true);
Assert.assertTrue(blockchainRepository.updateBlockchainMeta(blockchainMeta));

Map<String, String> partialClientConfig = new HashMap<>();
partialClientConfig.put(Constants.HETEROGENEOUS_BBC_CONTEXT, JSON.toJSONString(blockchainProperties1.getBbcContext()));
blockchainManager.updateBlockchain(
antChainDotComProduct,
antChainDotComBlockchainId,
"",
blockchainMeta.getAlias(),
blockchainMeta.getDesc(),
partialClientConfig
);

BlockchainMeta updatedMeta = blockchainManager.getBlockchainMetaByDomain(antChainDotComDomain);
Assert.assertEquals(PS_ID, updatedMeta.getPluginServerId());
Assert.assertEquals(initBlockHeight, updatedMeta.getProperties().getInitBlockHeight().longValue());
Assert.assertEquals(amAddr, updatedMeta.getProperties().getAmClientContractAddress());
Assert.assertEquals(sdpAddr, updatedMeta.getProperties().getSdpMsgContractAddress());
Assert.assertEquals(ptcAddr, updatedMeta.getProperties().getPtcContractAddress());
Assert.assertTrue(updatedMeta.getProperties().getIsDomainRegistered());

String newPtcAddr = "PTC_CONTRACT_UPDATED";
partialClientConfig.clear();
partialClientConfig.put("ptc_contract_address", newPtcAddr);
blockchainManager.updateBlockchain(
antChainDotComProduct,
antChainDotComBlockchainId,
"",
blockchainMeta.getAlias(),
blockchainMeta.getDesc(),
partialClientConfig
);

updatedMeta = blockchainManager.getBlockchainMetaByDomain(antChainDotComDomain);
Assert.assertEquals(PS_ID, updatedMeta.getPluginServerId());
Assert.assertEquals(initBlockHeight, updatedMeta.getProperties().getInitBlockHeight().longValue());
Assert.assertEquals(amAddr, updatedMeta.getProperties().getAmClientContractAddress());
Assert.assertEquals(sdpAddr, updatedMeta.getProperties().getSdpMsgContractAddress());
Assert.assertEquals(newPtcAddr, updatedMeta.getProperties().getPtcContractAddress());
Assert.assertTrue(updatedMeta.getProperties().getIsDomainRegistered());
}

@Test
public void testUpdateBlockchainProperty() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ public void updateProperties(BlockchainProperties properties) {
if (StrUtil.isNotEmpty(properties.getSdpMsgContractAddress())) {
this.properties.setSdpMsgContractAddress(properties.getSdpMsgContractAddress());
}
if (StrUtil.isNotEmpty(properties.getPtcContractAddress())) {
this.properties.setPtcContractAddress(properties.getPtcContractAddress());
}
if (ObjectUtil.isNotNull(properties.getAnchorRuntimeStatus())) {
this.properties.setAnchorRuntimeStatus(properties.getAnchorRuntimeStatus());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public void updateBlockchain(String product, String blockchainId, String pluginS
blockchainMeta.setAlias(alias);
blockchainMeta.setDesc(desc);
blockchainMeta.updateProperties(blockchainProperties);
if (!updateBlockchainMeta(new BlockchainMeta(product, blockchainId, alias, desc, blockchainProperties))) {
if (!updateBlockchainMeta(blockchainMeta)) {
throw new RuntimeException(
StrUtil.format(
"failed to update meta for blockchain {} - {} into DB",
Expand Down