Skip to content

Commit 0ffa34e

Browse files
committed
actions test
1 parent b6ff035 commit 0ffa34e

5 files changed

Lines changed: 173 additions & 33 deletions

File tree

.github/workflows/release-reproducible-smart-contract.yaml

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
env:
1111
REGISTRY: docker.io
1212
SERVICE_NAME: 'verifiable-sc'
13-
SOURCE_IMAGE_TAG: 'rust:1.85.0'
13+
RUST_VERSION: '1.85.0'
1414

1515
jobs:
1616
build-and-push-image:
@@ -21,50 +21,32 @@ jobs:
2121
uses: actions/checkout@v4
2222
with:
2323
submodules: recursive
24-
- run: |
25-
rustup update stable
26-
rustup default stable
27-
rustup target add wasm32-unknown-unknown
28-
# - uses: cachix/install-nix-action@v31
24+
- uses: actions-rust-lang/setup-rust-toolchain@v1
25+
with:
26+
toolchain: ${{ env.RUST_VERSION }}
27+
target: wasm32-unknown-unknown
28+
- run: docker build -f ./reproducible/build.Dockerfile --build-arg source_image="rust:$RUST_VERSION" -t "concordium/$SERVICE_NAME:$RUST_VERSION" ./reproducible
2929
- name: Test smart contract
30-
env:
31-
TAG: ${{ github.ref_name }}
32-
working-directory: ./concordium-base/smart-contracts/rust-contracts/example-contracts/fib
30+
working-directory: ./reproducible/example-contract
3331
run: |
34-
docker build -f "$GITHUB_WORKSPACE/reproducible/build.Dockerfile" --build-arg source_image="$SOURCE_IMAGE_TAG" -t local-image "$GITHUB_WORKSPACE/reproducible"
35-
cargo run --manifest-path "$GITHUB_WORKSPACE/cargo-concordium/Cargo.toml"
36-
# cargo run --manifest-path "$GITHUB_WORKSPACE/cargo-concordium/Cargo.toml" -- concordium build --verifiable "localhost/local-image:latest"
37-
# cargo run --manifest-path "$GITHUB_WORKSPACE/cargo-concordium/Cargo.toml" -- concordium verify-build --module ./concordium-out/module.wasm.v1 --source ./concordium-out/module.wasm.v1.tar
32+
CARGO_CONCORDIUM="cargo run --manifest-path $GITHUB_WORKSPACE/cargo-concordium/Cargo.toml --target x86_64-unknown-linux-gnu -- concordium"
33+
$CARGO_CONCORDIUM build --verifiable "concordium/$SERVICE_NAME:$RUST_VERSION"
34+
$CARGO_CONCORDIUM verify-build --module ./concordium-out/module.wasm.v1 --source ./concordium-out/module.wasm.v1.tar
3835
- name: Extract version from git tag
39-
id: meta
4036
env:
4137
TAG: ${{ github.ref_name }}
4238
run: |
4339
# Extract version by splitting on "/" and taking the second part
4440
TAG_VERSION=$(echo "$TAG" | cut -d '/' -f2)
45-
IMG_VERSION=$(echo "$SOURCE_IMAGE_TAG" | cut -d ':' -f2)
46-
47-
if [ $TAG_VERSION != $IMG_VERSION ]; then
48-
echo "Tag version does not match the source image version."
41+
if [ "$TAG_VERSION" != "$RUST_VERSION" ]; then
42+
echo "Tag version does not match the declared rust version."
4943
exit 1
5044
fi
51-
52-
# Save tag as fx "docker.io/concordium/verifiable-sc-1.85.0"
53-
echo "tag=$REGISTRY/concordium/$SERVICE_NAME-$TAG_VERSION" >> $GITHUB_OUTPUT
54-
# Uses the `docker/login-action` action to log in to the Container registry.
5545
# - name: Log in to the Container registry
5646
# uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
5747
# with:
5848
# registry: ${{ env.REGISTRY }}
5949
# username: ${{ secrets.DOCKERHUB_USERNAME }}
6050
# password: ${{ secrets.DOCKERHUB_TOKEN }}
61-
# - name: Build and push Docker image
62-
# uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
63-
# with:
64-
# context: .
65-
# file: ./reproducible/build.Dockerfile
66-
# push: true
67-
# platforms: linux/amd64
68-
# tags: ${{ steps.meta.outputs.tag }}
69-
# build-args: |
70-
# source_image=${{ env.SOURCE_IMAGE_TAG }}
51+
# - name: Push the image
52+
# run: docker push "concordium/$SERVICE_NAME:$RUST_VERSION"

reproducible/build.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# to copy data in and out of the container. The image also adds
66
# wasm32-unknown-unknown target.
77

8-
ARG source_image=rust:1.90.0
8+
ARG source_image=rust:1.86.0
99
FROM ${source_image} AS build
1010

1111
RUN rustup target add wasm32-unknown-unknown

reproducible/example-contract/Cargo.lock

Lines changed: 95 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[package]
2+
name = "piggy-bank-part1"
3+
version = "0.1.1"
4+
authors = ["Concordium <developers@concordium.com>"]
5+
edition = "2021"
6+
license = "MPL-2.0"
7+
description = "Piggy bank smart contract part 1."
8+
homepage = "https://github.com/concordium/concordium-rust-smart-contracts"
9+
repository = "https://github.com/concordium/concordium-rust-smart-contracts"
10+
readme = "../README.md"
11+
12+
[lib]
13+
crate-type = ["cdylib", "rlib"]
14+
15+
[features]
16+
default = ["std", "bump_alloc"]
17+
std = ["concordium-std/std"]
18+
bump_alloc = ["concordium-std/bump_alloc"]
19+
20+
[dependencies]
21+
concordium-std = "10"
22+
# [dependencies.concordium-std]
23+
# version = "10"
24+
# path = "../../../concordium-std"
25+
# default-features = false
26+
27+
[profile.release]
28+
opt-level = 3
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use concordium_std::*;
2+
3+
#[derive(Debug, SchemaType, Serialize, PartialEq, Eq, Clone, Copy)]
4+
enum PiggyBankState {
5+
Intact,
6+
Smashed,
7+
}
8+
9+
#[init(contract = "PiggyBank")]
10+
fn piggy_init(_ctx: &InitContext, _state_builder: &mut StateBuilder) -> InitResult<PiggyBankState> {
11+
Ok(PiggyBankState::Intact)
12+
}
13+
14+
#[receive(contract = "PiggyBank", name = "insert", payable)]
15+
fn piggy_insert(
16+
_ctx: &ReceiveContext,
17+
host: &Host<PiggyBankState>,
18+
_amount: Amount,
19+
) -> ReceiveResult<()> {
20+
ensure!(*host.state() == PiggyBankState::Intact);
21+
Ok(())
22+
}
23+
24+
#[receive(contract = "PiggyBank", name = "smash", mutable)]
25+
fn piggy_smash(ctx: &ReceiveContext, host: &mut Host<PiggyBankState>) -> ReceiveResult<()> {
26+
let owner = ctx.owner();
27+
let sender = ctx.sender();
28+
29+
ensure!(sender.matches_account(&owner));
30+
ensure!(*host.state() == PiggyBankState::Intact);
31+
*host.state_mut() = PiggyBankState::Smashed;
32+
33+
let balance = host.self_balance();
34+
Ok(host.invoke_transfer(&owner, balance)?)
35+
}

0 commit comments

Comments
 (0)