Skip to content

Commit

Permalink
Merge pull request godwokenrises#1 from TheWaWaR/setup-ci
Browse files Browse the repository at this point in the history
Setup CI
  • Loading branch information
TheWaWaR authored Jan 11, 2021
2 parents 6bc7ff4 + babb1c0 commit 344dcea
Show file tree
Hide file tree
Showing 12 changed files with 959 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ dkms.conf

build/
target/
integration-test/
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
language: rust
rust:
- stable
before_script:
- rustup component add rustfmt
- rustup component add clippy
- cargo install moleculec
stages:
- Test
jobs:
include:
- stage: Test
name: Integration-Test
script:
- bash devtools/ci/integration-test.sh
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ phf = "0.7.21"
[build-dependencies]
includedir_codegen = "0.5.0"
blake2b-rs = "0.1.5"
faster-hex = "0.4.1"
faster-hex = "0.4.1"
26 changes: 18 additions & 8 deletions c/polyjuice.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
#include <evmc/evmc.h>
#include <evmone/evmone.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "ckb_syscalls.h"
#include "godwoken.h"

#include <ethash/keccak.hpp>
#include <evmc/evmc.h>
#include <evmc/evmc.hpp>
#include <evmone/evmone.h>

#include "ckb_syscalls.h"
#include "common.h"
#include "godwoken.h"
#include "gw_syscalls.h"
#include "sudt_utils.h"

Expand Down Expand Up @@ -131,14 +132,14 @@ int parse_args(struct evmc_message* msg, uint128_t* gas_price,
debug_print_int("[flags]", flags);

/* args[2..10] gas limit */
int64_t gas_limit = (int64_t) * ((uint64_t*)(args + offset));
int64_t gas_limit = (int64_t) (*(uint64_t*)(args + offset));
offset += 8;
debug_print_int("[gas_limit]", gas_limit);

/* args[10..26] gas price */
*gas_price = *((uint128_t*)(args + offset));
offset += 16;
debug_print_int("[gas_price]", (int64_t)gas_price);
debug_print_int("[gas_price]", (int64_t)(*gas_price));

/* args[26..58] transfer value */
evmc_uint256be value = *((evmc_uint256be*)(args + offset));
Expand All @@ -158,7 +159,7 @@ int parse_args(struct evmc_message* msg, uint128_t* gas_price,
ckb_debug("invalid polyjuice transaction");
return -1;
}
if (kind != EVMC_CALL || kind != EVMC_CREATE) {
if (kind != EVMC_CALL && kind != EVMC_CREATE) {
ckb_debug("invalid call kind");
return -1;
}
Expand Down Expand Up @@ -392,6 +393,7 @@ size_t copy_code(struct evmc_host_context* context, const evmc_address* address,
if (ret != 0) {
return ret;
}
debug_print_data("code slice", buffer_data, buffer_size);
ckb_debug("END copy_code");
return 0;
}
Expand Down Expand Up @@ -645,7 +647,7 @@ int handle_message(gw_context_t* ctx, uint32_t parent_from_id,
memcpy(script_code_hash, code_hash_seg.ptr, 32);
script_hash_type = *hash_type_seg.ptr;
sudt_id = *(uint32_t*)(raw_args_seg.ptr);
free((void*)script_seg.ptr);
debug_print_int("sudt id", sudt_id);
has_touched = true;
}

Expand Down Expand Up @@ -842,8 +844,16 @@ int run_polyjuice() {
return -1;
}
uint128_t fee = gas_price * (uint128_t)(msg.gas - res.gas_left);
debug_print_int("gas limit", msg.gas);
debug_print_int("gas left", res.gas_left);
debug_print_int("gas price", gas_price);
debug_print_int("fee", fee);
ret = sudt_transfer(&context, sudt_id, context.transaction_context.from_id,
context.block_info.aggregator_id, fee);
if (ret != 0) {
debug_print_int("pay fee to aggregator failed", ret);
return ret;
}

ret = gw_finalize(&context);
if (ret != 0) {
Expand Down
28 changes: 28 additions & 0 deletions devtools/ci/integration-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

set -x
set -e

SCRIPT_DIR=$(realpath $(dirname $0))
PROJECT_ROOT=$(dirname $(dirname $SCRIPT_DIR))
TESTS_DIR=$PROJECT_ROOT/polyjuice-tests
DEPS_DIR=$PROJECT_ROOT/integration-test
GODWOKEN_DIR=$DEPS_DIR/godwoken

mkdir -p $DEPS_DIR
if [ -d "$GODWOKEN_DIR" ]
then
echo "godwoken project already exists"
else
git clone https://github.com/nervosnetwork/godwoken.git $GODWOKEN_DIR
fi

mkdir -p $GODWOKEN_DIR/c/build
cp $SCRIPT_DIR/*generator $SCRIPT_DIR/*validator $GODWOKEN_DIR/c/build

cd $PROJECT_ROOT
git submodule update --init --recursive
make all-via-docker

cd $TESTS_DIR
export RUST_BACKTRACE=full
cargo test -- --nocapture
Binary file added devtools/ci/meta-contract-generator
Binary file not shown.
Binary file added devtools/ci/meta-contract-validator
Binary file not shown.
Binary file added devtools/ci/sudt-generator
Binary file not shown.
Binary file added devtools/ci/sudt-validator
Binary file not shown.
Loading

0 comments on commit 344dcea

Please sign in to comment.