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

Commit

Permalink
Merge pull request #3 from AntChainOpenLabs/test/unit_test
Browse files Browse the repository at this point in the history
[fix][*][*] fix some problems and add workflow
  • Loading branch information
zouxyan authored Nov 20, 2023
2 parents acb5ef4 + 256271e commit eecaa74
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 38 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/install_acbsdk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#
# Copyright 2023 Ant Group
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#!/bin/bash

CURR_DIR="$(cd `dirname $0`; pwd)"

echo "install BID SDK ..."
git clone -b release/1.0.0 https://github.com/caict-4iot-dev/BID-SDK-JAVA.git
cd BID-SDK-JAVA/BID-SDK
mvn install -Dmaven.test.skip=true
cd -
echo "install BID SDK finished"

echo "install ACB SDK ..."
git clone -b feat/bcdns_support https://github.com/AntChainOpenLabs/AntChainBridgePluginSDK.git
cd AntChainBridgePluginSDK/antchain-bridge-commons
mvn install -Dmaven.test.skip=true
cd -
cd AntChainBridgePluginSDK/antchain-bridge-spi
mvn install -Dmaven.test.skip=true
cd -
echo "install ACB SDK finished"
39 changes: 39 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven

# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Java CI with Maven

on:
push:
branches: [ "main", "develop", "test/**" ]
pull_request:
branches: [ "main", "develop" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up JDK 8
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'temurin'
cache: maven
- name: Install deps
run: bash .github/workflows/install_acbsdk.sh
- name: Build with Maven
run: mvn -B package --file pom.xml
- name: Test
run: mvn test --file pom.xml

# Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive
# - name: Update dependency graph
# uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6
12 changes: 12 additions & 0 deletions r-bootstrap/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@
</nonFilteredFileExtensions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.2</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>3.2.2</version>
</dependency>
</dependencies>
</plugin>
<!-- <plugin>-->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- <artifactId>maven-assembly-plugin</artifactId>-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public abstract class TestBase {

@BeforeClass
public static void beforeTest() throws Exception {
// if the embedded redis can't start correctly,
// try to use local redis server binary to start it.
redisServer = new MyRedisServer(
RedisExecProvider.defaultProvider()
.override(OS.MAC_OS_X, Architecture.x86_64, "/usr/local/bin/redis-server")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright 2023 Ant Group
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

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

import java.nio.charset.StandardCharsets;

import javax.annotation.Resource;

import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.io.FileUtil;
import com.alipay.antchain.bridge.relayer.bootstrap.TestBase;
import com.alipay.antchain.bridge.relayer.commons.constant.PluginServerStateEnum;
import com.alipay.antchain.bridge.relayer.commons.model.PluginServerDO;
import com.alipay.antchain.bridge.relayer.commons.model.PluginServerInfo;
import com.alipay.antchain.bridge.relayer.dal.repository.IPluginServerRepository;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;

public class PluginServerRepositoryTest extends TestBase {

public static PluginServerDO pluginServerDO;

@BeforeClass
public static void setUp() throws Exception {
pluginServerDO = new PluginServerDO();
pluginServerDO.setPsId(testchain1Meta.getPluginServerId());
pluginServerDO.setAddress("localhost:9090");
pluginServerDO.setState(PluginServerStateEnum.INIT);
PluginServerDO.PluginServerProperties properties = new PluginServerDO.PluginServerProperties();
properties.setPluginServerCert(FileUtil.readString("node_keys/ps/relayer.crt", StandardCharsets.UTF_8));
pluginServerDO.setProperties(properties);
}

@Resource
private IPluginServerRepository pluginServerRepository;

@Test
public void testInsertNewPluginServer() {
pluginServerRepository.insertNewPluginServer(pluginServerDO);
}

@Test
public void testUpdatePluginServerInfo() {
savePS();

pluginServerRepository.updatePluginServerInfo(
pluginServerDO.getPsId(),
new PluginServerInfo(
PluginServerStateEnum.READY,
ListUtil.toList(testchain1Meta.getProduct()),
ListUtil.toList(antchainSubject.getDomainName().getDomain())
)
);

PluginServerInfo pluginServerInfo = pluginServerRepository.getPluginServerInfo(pluginServerDO.getPsId());
Assert.assertNotNull(pluginServerInfo);
Assert.assertEquals(
PluginServerStateEnum.READY,
pluginServerInfo.getState()
);
Assert.assertEquals(
testchain1Meta.getProduct(),
pluginServerInfo.getProducts().get(0)
);
Assert.assertEquals(
antchainSubject.getDomainName().getDomain(),
pluginServerInfo.getDomains().get(0)
);
}

private void savePS() {
pluginServerRepository.insertNewPluginServer(pluginServerDO);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import java.io.IOException;

import cn.hutool.core.util.StrUtil;
import cn.hutool.system.SystemUtil;
import redis.embedded.RedisExecProvider;
import redis.embedded.RedisServer;

Expand All @@ -29,6 +31,9 @@ public MyRedisServer(RedisExecProvider redisExecProvider, Integer port) throws I

@Override
protected String redisReadyPattern() {
return ".*Ready to accept connections tcp.*";
if (SystemUtil.getOsInfo().isMac() && StrUtil.equalsIgnoreCase(SystemUtil.getOsInfo().getArch(), "x86_64")) {
return ".*Ready to accept connections tcp.*";
}
return super.redisReadyPattern();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -297,41 +297,6 @@ public Long queryLatestHeight() {
return response.getBbcResp().getQueryLatestHeightResponse().getHeight();
}

@Override
public boolean hasTPBTA(String s) {
return false;
}

@Override
public byte[] getTPBTA(String s) {
return new byte[0];
}

@Override
public boolean ifBlockchainProductSupported(String s) {
return false;
}

@Override
public void addTPBTA(String s, byte[] bytes) {

}

@Override
public void approveProtocol(String s) {

}

@Override
public void disapproveProtocol(String s) {

}

@Override
public void setOwner(String s) {

}

private void handleErrorCode(Response response) {
if (response.getCode() == 217) {
response = this.blockingStub.bbcCall(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public void updatePluginServerInfo(String psId, PluginServerInfo info) {
PluginServerObjectsEntity.builder()
.products(StrUtil.join(",", info.getProducts()))
.domains(StrUtil.join(",", info.getDomains()))
.state(info.getState())
.build(),
new LambdaUpdateWrapper<PluginServerObjectsEntity>()
.eq(PluginServerObjectsEntity::getPsId, psId)
Expand Down Expand Up @@ -222,8 +223,8 @@ public PluginServerInfo getPluginServerInfo(String psId) {
}
return new PluginServerInfo(
entity.getState(),
StrUtil.split(",", entity.getProducts()),
StrUtil.split(",", entity.getDomains())
StrUtil.split(entity.getProducts(), ","),
StrUtil.split(entity.getDomains(), ",")
);
} catch (Exception e) {
throw new AntChainBridgeRelayerException(
Expand Down

0 comments on commit eecaa74

Please sign in to comment.