Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Jenkins CI #32

Merged
merged 6 commits into from
Mar 30, 2019
Merged
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
145 changes: 145 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
pipeline {
agent none
stages {
stage('Install Rust') {
parallel {
stage('macos') {
agent { label 'macos' }
steps {
sh './ci/install_rust.sh'
}
}
stage('linux') {
agent { label 'linux' }
steps {
sh './ci/install_rust.sh'
}
}
stage('windows') {
agent { label 'windows' }
steps {
powershell '& ./ci/install_rust.ps1'
}
}
}
}
stage('Build') {
parallel {
stage('macos') {
agent {
label 'macos'
}
stages {
stage('stable') {
steps {
sh './ci/build.sh'
}
}
stage('beta') {
steps {
sh './ci/build.sh +beta'
}
}
stage('nightly') {
steps {
sh './ci/build.sh +nightly'
}
}
}
}
stage('linux') {
agent {
label 'linux'
}
stages {
stage('stable') {
steps {
sh './ci/build.sh'
}
}
stage('beta') {
steps {
sh './ci/build.sh +beta'
}
}
stage('nightly') {
steps {
sh './ci/build.sh +nightly'
}
}
}
}
stage('windows') {
agent {
label 'windows'
}
stages {
stage('stable') {
steps {
bat 'call ./ci/build.bat'
}
}
}
}
}
}
stage('Test') {
parallel {
stage('macos') {
agent {
label 'macos'
}
steps {
sh './ci/test.sh'
}
}
stage('linux') {
agent {
label 'linux'
}
steps {
sh './ci/test.sh'
}
}
stage('windows') {
agent {
label 'windows'
}
steps {
bat 'call ./ci/test.bat'
}
}
}
}
stage('Lint') {
agent { node { label 'macos' } }
steps {
sh 'cargo check 2>&1 | tee rustc.build_log'
sh 'cargo clean'
sh 'cargo clippy 2>&1 | tee clippy.build_log'
sh 'if grep -q "^error" clippy.build_log; then echo "clippy found a severe error"; exit 1; fi'
}
post {
always {
script {
recordIssues enabledForFailure: true,
qualityGates: [[threshold: 10, type: 'TOTAL', unstable: true]],
healthy: 5, unhealthy: 20, minimumSeverity: 'HIGH',
tools: [
groovyScript(parserId: 'clippy-warnings', pattern: "clippy.build_log", reportEncoding:'UTF-8'),
groovyScript(parserId: 'rustc-warnings', pattern: "rustc.build_log", reportEncoding:'UTF-8')
]
}
}
}
}
stage('Rustfmt') {
agent {
label 'macos'
}
steps {
sh 'cargo fmt -- --check'
}
}
}
}
3 changes: 3 additions & 0 deletions ci/build.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
setx PATH "%PATH%;%USERPROFILE%\.cargo\bin"
set PATH="%PATH%;%USERPROFILE%\.cargo\bin"
%USERPROFILE%\.cargo\bin\cargo build
6 changes: 6 additions & 0 deletions ci/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -e
set -x

source $HOME/.cargo/env
cargo $@ build
7 changes: 7 additions & 0 deletions ci/install_rust.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
if (Test-Path -Path C:\Users\jenkins\.cargo\bin\rustup.exe) {
exit
}

$client = new-object System.Net.WebClient
$client.DownloadFile('https://win.rustup.rs', "$pwd\rustup-init.exe")
.\rustup-init.exe -y
24 changes: 24 additions & 0 deletions ci/install_rust.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

# Fail fast if any commands exists with error
set -e

# Print all executed commands
set -x

# Download rustup script and execute it
curl https://sh.rustup.rs -sSf > ./rustup.sh
chmod +x ./rustup.sh
./rustup.sh -y

# Load new environment
source $HOME/.cargo/env

# Install nightly and beta toolchains, but set stable as a default
rustup install nightly
rustup install beta
rustup default stable

# Install aux components, clippy for linter, rustfmt for formatting
rustup component add clippy
rustup component add rustfmt
3 changes: 3 additions & 0 deletions ci/test.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
setx PATH "%PATH%;%USERPROFILE%\.cargo\bin"
set PATH="%PATH%;%USERPROFILE%\.cargo\bin"
%USERPROFILE%\.cargo\bin\cargo test --all
6 changes: 6 additions & 0 deletions ci/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
set -e
set -x

source $HOME/.cargo/env
cargo $@ test --all
7 changes: 4 additions & 3 deletions src/commit/account.rs
Original file line number Diff line number Diff line change
@@ -410,7 +410,7 @@ impl<'a, A: AccountPatch> AccountState<'a, A> {
self.orig_storage
.borrow_mut()
.entry(address)
.or_insert(Storage::new(address, true))
.or_insert_with(|| Storage::new(address, true))
.commit(index, value)?
}
AccountCommitment::Nonexist(address) => {
@@ -554,8 +554,9 @@ impl<'a, A: AccountPatch> AccountState<'a, A> {
/// Read an original (pre-execution) value from an account storage
pub fn storage_read_orig(&self, address: Address, index: U256) -> Result<M256, RequireError> {
let mut orig_storage = self.orig_storage.borrow_mut();
let orig_account_storage = orig_storage.entry(address).or_insert(Storage::new(address, true));

let orig_account_storage = orig_storage
.entry(address)
.or_insert_with(|| Storage::new(address, true));
orig_account_storage.read(index)
}

17 changes: 7 additions & 10 deletions src/eval/cost.rs
Original file line number Diff line number Diff line change
@@ -61,12 +61,10 @@ fn sstore_cost<M: Memory, P: Patch>(state: &State<M, P>) -> Gas {
G_SNOOP.into()
}
}
} else if value != M256::zero() && state.account_state.storage_read(address, index).unwrap() == M256::zero() {
G_SSET.into()
} else {
if value != M256::zero() && state.account_state.storage_read(address, index).unwrap() == M256::zero() {
G_SSET.into()
} else {
G_SRESET.into()
}
G_SRESET.into()
}
}

@@ -379,12 +377,11 @@ pub fn gas_refund<M: Memory, P: Patch>(instruction: Instruction, state: &State<M
}

refund
} else if value == M256::zero() && state.account_state.storage_read(address, index).unwrap() != M256::zero()
{
R_SRESET
} else {
if value == M256::zero() && state.account_state.storage_read(address, index).unwrap() != M256::zero() {
R_SRESET
} else {
0
}
0
}
}
Instruction::SUICIDE => {
2 changes: 1 addition & 1 deletion src/eval/lifecycle.rs
Original file line number Diff line number Diff line change
@@ -116,7 +116,7 @@ impl<'a, M: Memory, P: Patch> Machine<'a, M, P> {
}

/// Deposit code for a ContractCreation transaction or a CREATE opcode.
#[cfg_attr(feature = "cargo-clippy", allow(collapsible_if))]
#[allow(clippy::collapsible_if)]
pub fn code_deposit(&mut self) {
match self.status() {
MachineStatus::ExitedOk | MachineStatus::ExitedErr(_) => (),
2 changes: 1 addition & 1 deletion src/eval/mod.rs
Original file line number Diff line number Diff line change
@@ -247,7 +247,7 @@ impl<'a, M: Memory, P: Patch> Machine<'a, M, P> {

/// Create a new runtime.
pub fn new(patch: &'a P, context: Context, depth: usize) -> Self {
let account_patch = patch.account_patch().clone();
let account_patch = patch.account_patch();
Self::with_states(patch, context, depth, AccountState::new(account_patch))
}

5 changes: 1 addition & 4 deletions src/eval/run/bitwise.rs
Original file line number Diff line number Diff line change
@@ -80,10 +80,7 @@ pub fn sar<M: Memory, P: Patch>(state: &mut State<M, P>) {
let shift: u64 = shift.into();

match value.0 {
Sign::Plus | Sign::NoSign => {
let shifted = value.1 >> shift as usize;
shifted
}
Sign::Plus | Sign::NoSign => value.1 >> shift as usize,
Sign::Minus => {
let shifted = ((value.1 - M256::one()) >> shift as usize) + M256::one();
MI256(Sign::Minus, shifted).into()
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -350,7 +350,7 @@ impl<'a, M: Memory, P: Patch> VM for ContextVM<'a, M, P> {
Ok(())
}

#[cfg_attr(feature = "cargo-clippy", allow(single_match))]
#[allow(clippy::single_match)]
fn status(&self) -> VMStatus {
match self.machines.last().unwrap().status().clone() {
MachineStatus::ExitedNotSupported(err) => return VMStatus::ExitedNotSupported(err),
12 changes: 3 additions & 9 deletions src/patch/precompiled.rs
Original file line number Diff line number Diff line change
@@ -169,29 +169,23 @@ fn kececrec(data: &[u8]) -> Result<[u8; 32], Error> {
#[cfg(feature = "rust-secp256k1")]
fn kececrec(data: &[u8]) -> Result<[u8; 32], Error> {
let mut message_raw = [0u8; 32];
for i in 0..32 {
message_raw[i] = data[i];
}
message_raw[..32].clone_from_slice(&data[..32]);
let message = Message::parse(&message_raw);
let recid_raw = match data[63] {
27 | 28 if data[32..63] == [0; 31] => data[63] - 27,
_ => return Err(Error::InvalidRecoveryId),
};
let recid = RecoveryId::parse(recid_raw)?;
let mut sig_raw = [0u8; 64];
for i in 0..64 {
sig_raw[i] = data[64 + i];
}
sig_raw[..64].clone_from_slice(&data[64..128]);
let sig = Signature::parse(&sig_raw);
let recovered = recover(&message, &sig, &recid)?;
let key = recovered.serialize();

let ret_generic = Keccak256::digest(&key[1..65]);
let mut ret = [0u8; 32];

for i in 0..32 {
ret[i] = ret_generic[i];
}
ret[..32].clone_from_slice(&ret_generic[..32]);

Ok(ret)
}
4 changes: 2 additions & 2 deletions src/transaction.rs
Original file line number Diff line number Diff line change
@@ -338,7 +338,7 @@ impl<'a, M: Memory, P: Patch> TransactionVM<'a, M, P> {
block: HeaderParams,
) -> Result<Self, PreExecutionError> {
let valid = transaction.to_valid(patch)?;
let account_patch = patch.account_patch().clone();
let account_patch = patch.account_patch();
let mut vm = TransactionVM(TransactionVMState::Constructing {
patch,
transaction: valid,
@@ -353,7 +353,7 @@ impl<'a, M: Memory, P: Patch> TransactionVM<'a, M, P> {
/// Create a new VM using the given transaction, block header and
/// patch. This VM runs at the transaction level.
pub fn new(patch: &'a P, transaction: ValidTransaction, block: HeaderParams) -> Self {
let account_patch = patch.account_patch().clone();
let account_patch = patch.account_patch();
TransactionVM(TransactionVMState::Constructing {
patch,
transaction,