Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
[feat][r-core][*]: fix update blockchain Anchor
Browse files Browse the repository at this point in the history
  • Loading branch information
dawn-to-dusk committed Jan 2, 2024
1 parent 6658dfa commit 7269dd8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@

package com.alipay.antchain.bridge.relayer.bootstrap.manager;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.annotation.Resource;

import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alipay.antchain.bridge.pluginserver.service.CrossChainServiceGrpc;
import com.alipay.antchain.bridge.relayer.bootstrap.TestBase;
import com.alipay.antchain.bridge.relayer.commons.constant.BlockchainStateEnum;
Expand Down Expand Up @@ -75,17 +82,40 @@ public void testAddBlockchain() {
}

@Test
public void testUpdateBlockchainProperty() {
public void testUpdateBlockchainAnchor() throws IOException {

blockchainManager.updateBlockchainProperty(
Assert.assertTrue(blockchainManager.hasBlockchain(antChainDotComDomain));

BlockchainMeta blockchainMeta = blockchainManager.getBlockchainMetaByDomain(antChainDotComDomain);
String amAddr = "{\\\"evm\\\":\\\"AM_EVM_CONTRACT_bccb26ef-4179-42cf-aabb-082f83c4082e\\\", \\\"wasm\\\":\\\"AM_WASM_CONTRACT_9643c28d-6aac-4ef8-b7a7-edc81a402442\\\"}";
blockchainMeta.getProperties().setAmClientContractAddress(amAddr);
String clientConfig = JSONObject.toJSONString(blockchainMeta.getProperties(), SerializerFeature.PrettyFormat);
if (!JSONUtil.isTypeJSON(clientConfig.trim())) {
clientConfig = new String(Files.readAllBytes(Paths.get(clientConfig)));
}

blockchainManager.updateBlockchain(
antChainDotComProduct,
antChainDotComBlockchainId,
Constants.AM_SERVICE_STATUS,
OnChainServiceStatusEnum.INIT.name()
"",
blockchainMeta.getAlias(),
blockchainMeta.getDesc(),
JSONObject.parseObject(clientConfig)
.entrySet().stream().collect(
Collectors.toMap(
Map.Entry::getKey,
entry -> entry.getValue().toString()
)
)
);
BlockchainMeta blockchainMeta = blockchainManager.getBlockchainMeta(antChainDotComProduct, antChainDotComBlockchainId);

blockchainMeta = blockchainManager.getBlockchainMetaByDomain(antChainDotComDomain);

Assert.assertNotNull(blockchainMeta);
Assert.assertEquals(OnChainServiceStatusEnum.INIT, blockchainMeta.getProperties().getAmServiceStatus());
Assert.assertEquals(amAddr, blockchainMeta.getProperties().getAmClientContractAddress());
Assert.assertEquals(antChainDotComProduct, blockchainMeta.getProduct());
Assert.assertEquals(antChainDotComBlockchainId, blockchainMeta.getBlockchainId());
Assert.assertEquals(PS_ID, blockchainMeta.getPluginServerId());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,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(new BlockchainMeta(product, blockchainId, alias, desc, blockchainProperties))) {
throw new RuntimeException(
StrUtil.format(
"failed to update meta for blockchain {} - {} into DB",
Expand All @@ -180,7 +180,7 @@ public void updateBlockchain(String product, String blockchainId, String pluginS
throw new AntChainBridgeRelayerException(
RelayerErrorCodeEnum.CORE_BLOCKCHAIN_ERROR,
e,
"failed to add new blockchain {} - {} with plugin server {}",
"failed to update blockchain {} - {}",
product, blockchainId
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ Object updateBlockchainAnchor(String... args) {
.entrySet().stream().collect(
Collectors.toMap(
Map.Entry::getKey,
entry -> (String) entry.getValue()
entry -> entry.getValue().toString()
)
)
);
Expand Down

0 comments on commit 7269dd8

Please sign in to comment.