Skip to content

Commit

Permalink
scan code with cobra (#376)
Browse files Browse the repository at this point in the history
* scan code with cobra
  • Loading branch information
HaoXuan40404 authored and bxq2011hust committed Aug 20, 2019
1 parent 5761137 commit 5ab3333
Show file tree
Hide file tree
Showing 12 changed files with 141 additions and 52 deletions.
16 changes: 16 additions & 0 deletions .ci/ci_check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -e

curl -LO https://raw.githubusercontent.com/FISCO-BCOS/FISCO-BCOS/master/tools/build_chain.sh && chmod u+x build_chain.sh
bash <(curl -s https://raw.githubusercontent.com/FISCO-BCOS/FISCO-BCOS/master/tools/ci/download_bin.sh) -b dev
echo "127.0.0.1:4 agency1 1,2,3" > ipconf
./build_chain.sh -e bin/fisco-bcos -f ipconf -p 30300,20200,8545 -v 2.0.0
./nodes/127.0.0.1/start_all.sh
./nodes/127.0.0.1/fisco-bcos -v
cp nodes/127.0.0.1/sdk/* src/integration-test/resources/
mv src/integration-test/resources/applicationContext-sample.xml src/integration-test/resources/applicationContext.xml
./gradlew verifyGoogleJavaFormat
./gradlew build
./gradlew test
./gradlew integrationTest
52 changes: 52 additions & 0 deletions .ci/ci_check_commit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

set -e

scan_code_script="python ~/cobra/cobra.py -t "

LOG_ERROR() {
content=${1}
echo -e "\033[31m${content}\033[0m"
}

LOG_INFO() {
content=${1}
echo -e "\033[32m${content}\033[0m"
}

execute_cmd() {
command="${1}"
eval ${command}
ret=$?
if [ $ret -ne 0 ];then
LOG_ERROR "FAILED of command: ${command}"
exit 1
else
LOG_INFO "SUCCESS of command: ${command}"
fi
}

scan_code()
{
# Redirect output to stderr.
exec 1>&2
for file in $(git diff-index --name-status HEAD^ | grep -v .ci | awk '{print $2}'); do
execute_cmd "${scan_code_script} $file -f json -o /tmp/report.json"
trigger_rules=$(jq -r '.' /tmp/report.json | grep 'trigger_rules' | awk '{print $2}' | sed 's/,//g')
echo "trigger_rules is ${trigger_rules}"
rm /tmp/report.json
if [ ${trigger_rules} -ne 0 ]; then
echo "######### ERROR: Scan code failed, please adjust them before commit"
exit 1
fi
done
}

install_cobra() {
git clone https://github.com/WhaleShark-Team/cobra.git ~/cobra
pip install -r ~/cobra/requirements.txt
cp ~/cobra/config.template ~/cobra/config
}

install_cobra
scan_code
59 changes: 38 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,53 @@ branches:
matrix:
fast_finish: true
include:
- os: linux
dist: xenial
sudo: required
- language: python
python: 3.6
dist: xenial
before_cache:
cache:
before_install:
script: |
bash .ci/ci_check_commit.sh
language: java
jdk:
- openjdk8
- language: java
jdk: openjdk8
os: linux
dist: xenial
sudo: required

- language: java
jdk: openjdk9
os: linux
dist: xenial
sudo: required

- language: java
jdk: openjdk10
os: linux
dist: xenial
sudo: required

- language: java
jdk: openjdk11
os: linux
dist: xenial
sudo: required

# - language: java
# jdk: openjdk11
# os: osx
# before_install:
# - brew install gradle && gradle wrapper

before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/

cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/

before_install:
- gradle wrapper

script: |
curl -LO https://raw.githubusercontent.com/FISCO-BCOS/FISCO-BCOS/master/tools/build_chain.sh && chmod u+x build_chain.sh
bash <(curl -s https://raw.githubusercontent.com/FISCO-BCOS/FISCO-BCOS/master/tools/ci/download_bin.sh) -b release-2.0.0
echo "127.0.0.1:4 agency1 1,2,3" > ipconf
./build_chain.sh -e bin/fisco-bcos -f ipconf -p 30300,20200,8545 -v 2.0.0
./nodes/127.0.0.1/start_all.sh
./nodes/127.0.0.1/fisco-bcos -v
cp nodes/127.0.0.1/sdk/* src/integration-test/resources/
mv src/integration-test/resources/applicationContext-sample.xml src/integration-test/resources/applicationContext.xml
./gradlew verifyGoogleJavaFormat
./gradlew build
./gradlew test
./gradlew integrationTest
bash .ci/ci_check.sh
Empty file modified gradlew
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.SSLException;

import org.fisco.bcos.channel.protocol.EnumSocketChannelAttributeKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -465,7 +464,9 @@ public void reconnect() {
socketChannel.remoteAddress().getAddress().getHostAddress();
int port = socketChannel.remoteAddress().getPort();

AttributeKey<String> attributeKey = AttributeKey.valueOf(EnumSocketChannelAttributeKey.CHANNEL_CONNECTED_KEY.getKey());
AttributeKey<String> attributeKey =
AttributeKey.valueOf(
EnumSocketChannelAttributeKey.CHANNEL_CONNECTED_KEY.getKey());
String connectTimePoint = ctx.getValue().channel().attr(attributeKey).get();

String host = hostAddress + ":" + port;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public static EnumChannelProtocolVersion getProtocolVersion(ChannelHandlerContex
int port = socketChannel.remoteAddress().getPort();

String host = hostAddress + ":" + port;
AttributeKey<ChannelProtocol> attributeKey = AttributeKey.valueOf(EnumSocketChannelAttributeKey.CHANNEL_PROTOCOL_KEY.getKey());
AttributeKey<ChannelProtocol> attributeKey =
AttributeKey.valueOf(EnumSocketChannelAttributeKey.CHANNEL_PROTOCOL_KEY.getKey());

if (ctx.channel().hasAttr(attributeKey)) {
ChannelProtocol channelProtocol = ctx.channel().attr(attributeKey).get();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package org.fisco.bcos.channel.protocol;

public enum EnumSocketChannelAttributeKey {

CHANNEL_PROTOCOL_KEY("CHANNEL_PROTOCOL_KEY"),
CHANNEL_CONNECTED_KEY("CHANNEL_CONNECTED_KEY");

private EnumSocketChannelAttributeKey(String key) {
this.key = key;
}

private String key;
CHANNEL_PROTOCOL_KEY("CHANNEL_PROTOCOL_KEY"),
CHANNEL_CONNECTED_KEY("CHANNEL_CONNECTED_KEY");

public String getKey() {
return key;
}
private EnumSocketChannelAttributeKey(String key) {
this.key = key;
}

public void setKey(String key) {
this.key = key;
}
private String key;

public String getKey() {
return key;
}

public void setKey(String key) {
this.key = key;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public byte[] encode(String value) throws JsonProcessingException {
break;
case VERSION_1:
{
result = value.getBytes();
result = value.getBytes();
}
break;
break;
default:
break;
}
Expand All @@ -62,7 +62,7 @@ public BcosHeartbeat decode(String data)
break;
case VERSION_1:
{
bcosHeartbeat.setHeartBeat(Integer.parseInt(data));
bcosHeartbeat.setHeartBeat(Integer.parseInt(data));
}
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public CompletableFuture<T> sendAsync() {
public Flowable<T> flowable() {
return new RemoteCall<>(this::send).flowable();
}

@JsonIgnore
public TransactionSucCallback getCallback() {
return callback;
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/org/fisco/bcos/web3j/tx/Contract.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ public static TransactionManager getTheTransactionManager(
NodeVersion.Version nodeVersion = web3j.getNodeVersion().send().getNodeVersion();
version = nodeVersion.getVersion();
supportedVersion = nodeVersion.getSupportedVersion();

if (EnumNodeVersion.BCOS_2_0_0_RC1.getVersion().equals(version) || EnumNodeVersion.BCOS_2_0_0_RC1.getVersion().equals(supportedVersion)) {

if (EnumNodeVersion.BCOS_2_0_0_RC1.getVersion().equals(version)
|| EnumNodeVersion.BCOS_2_0_0_RC1.getVersion().equals(supportedVersion)) {
version = EnumNodeVersion.BCOS_2_0_0_RC1.getVersion();
logger.info("fisco-bcos version:{}", version);
} else {
Expand Down Expand Up @@ -406,9 +407,11 @@ protected void asyncExecuteTransaction(Function function, TransactionSucCallback
gasProvider.getGasLimit(function.getName()),
callback);
} catch (IOException e) {
e.printStackTrace();
// e.print_Stack_Trace();
logger.error(" IOException, message:{}", e.getMessage());
} catch (TransactionException e) {
e.printStackTrace();
// e.print_Stack_Trace();
logger.error(" TransactionException, message:{}", e.getMessage());
}
}

Expand All @@ -423,7 +426,8 @@ protected String createTransactionSeq(Function function) {
gasProvider.getGasLimit(function.getName()));
return signedTransaction;
} catch (IOException e) {
e.printStackTrace();
// e.print_Stack_Trace();
logger.error(" IOException, message:{}", e.getMessage());
return "";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public void setCollector(PerformanceDTCollector collector) {

static Logger logger = LoggerFactory.getLogger(PerformanceDTCallback.class);

public PerformanceDTCallback() {
}
public PerformanceDTCallback() {}

@Override
public void onResponse(TransactionReceipt receipt) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package org.fisco.bcos.channel.test.parallel.precompile;

import java.math.BigInteger;
import org.fisco.bcos.channel.client.TransactionSucCallback;
import org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt;
Expand Down Expand Up @@ -53,8 +54,7 @@ public void setCollector(PerformanceDTCollector collector) {

static Logger logger = LoggerFactory.getLogger(PerformanceDTCallback.class);

public PerformanceDTCallback() {
}
public PerformanceDTCallback() {}

@Override
public void onResponse(TransactionReceipt receipt) {
Expand Down

0 comments on commit 5ab3333

Please sign in to comment.