Skip to content

Commit

Permalink
Merge pull request #8 from matthewhammer/candiff-release
Browse files Browse the repository at this point in the history
Use Candiff to compare logs
  • Loading branch information
matthewhammer authored Aug 26, 2020
2 parents 7685ba1 + d775747 commit 68a7c00
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 21 deletions.
28 changes: 8 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,7 @@ jobs:
tests:
runs-on: ubuntu-18.04
steps:
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Checkout candid repo
uses: actions/checkout@v2
with:
repository: dfinity/candid
- name: Install candid tools
run: |
cd tools/didc
cargo install --root /home/runner --path .
cd ..
cd candiff
cargo install --root /home/runner --path .
cd ../..
echo "::add-path::/home/runner/bin"
- uses: actions/checkout@v2
- name: "didc help (sanity check)"
run: didc --help
- name: "candiff help (sanity check)"
run: candiff --help
- name: "install dfx"
run: |
wget https://sdk.dfinity.org/install.sh
Expand All @@ -39,5 +19,13 @@ jobs:
run: dfx cache install
- name: "install vessel"
run: wget --output-document /home/runner/bin/vessel https://github.com/kritzcreek/vessel/releases/download/v0.4.1/vessel-linux64 && chmod +x /home/runner/bin/vessel
- name: "install candid tool"
run: wget --output-document /home/runner/bin/candiff https://github.com/dfinity/candid/releases/download/2020-08-18/candiff-linux64 && chmod +x /home/runner/bin/candiff
- name: "candiff help (sanity check)"
run: candiff --help
- name: "install didc tool"
run: wget --output-document /home/runner/bin/didc https://github.com/dfinity/candid/releases/download/2020-08-18/didc-linux64 && chmod +x /home/runner/bin/didc
- name: "didc help (sanity check)"
run: didc --help
- name: "test"
run: ./test.sh
23 changes: 23 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,30 @@ echo == Test BigMap service.
echo

dfx canister install BigMapPutGet

LOOP="(true)";
while [ "$LOOP" == "(true)" ]; do
LOOP=$(dfx canister call BigMapPutGet doNextCall)
done

dfx canister call BigMapPutGet getFullLog --output raw > BigMapPutGet.raw

echo BEGIN BigMapPutGet.raw
cat BigMapPutGet.raw
echo END BigMapPutGet.raw

echo BEGIN 'didc decode `cat BigMapPutGet.raw` > BigMapPutGet.log'
didc decode `cat BigMapPutGet.raw` -d .dfx/local/canisters/BigMapPutGet/BigMapPutGet.did -m getFullLog > BigMapPutGet.log
echo END 'didc decode `cat BigMapPutGet.raw`'

echo BEGIN "BigMapPutGet.log (latest-captured log)"
cat BigMapPutGet.log
echo END "BigMapPutGet.log"

echo BEGIN "test/BigMapPutGet.log (expected log)"
cat test/BigMapPutGet.log
echo END "test/BigMapPutGet.log"

echo BEGIN "candiff compares a expected log (left) and latest captured log (right):"
candiff diff "`cat test/BigMapPutGet.log`" "`cat BigMapPutGet.log`"
echo END candiff comparison.
1 change: 1 addition & 0 deletions test/BigMapPutGet.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(vec { record { 0 = variant { put = record { 0 = vec { 0; }; 1 = vec { 0; }; } }; 1 = variant { ok = variant { unit = null } }; }; record { 0 = variant { get = vec { 0; } }; 1 = variant { ok = variant { opt = variant { nat = 0 } } }; }; record { 0 = variant { put = record { 0 = vec { 0; }; 1 = vec { 0; }; } }; 1 = variant { ok = variant { unit = null } }; }; record { 0 = variant { put = record { 0 = vec { 1; }; 1 = vec { 1; }; } }; 1 = variant { ok = variant { unit = null } }; }; record { 0 = variant { get = vec { 0; } }; 1 = variant { ok = variant { opt = variant { nat = 0 } } }; }; record { 0 = variant { get = vec { 1; } }; 1 = variant { ok = variant { opt = variant { nat = 1 } } }; }; })
15 changes: 14 additions & 1 deletion test/BigMapPutGet.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Prim "mo:prim";
import BigMap "canister:BigMap";
import Iter "mo:base/Iter";
import Debug "mo:base/Debug";
import Buffer "mo:base/Buffer";

import TestBatch "../src/Batch";
import TestTypes "../src/Types";
Expand Down Expand Up @@ -43,7 +44,8 @@ actor {
};

// some defaults
var batch : TestBatch.Batch = newBatches([0, 1, 2, 4, 8
var batch : TestBatch.Batch = newBatches([0, 1
//,2, 4, 8 -- TEMP -- make this faster for CI iteration...
//,128 -- takes an hour or so
]);

Expand Down Expand Up @@ -73,12 +75,23 @@ actor {
Debug.print ("doNextCall - result = " # (debug_show r));
Debug.print "doNextCall - saving result...";
batch.saveResult(r);
callLog.add((c, r));
Debug.print "doNextCall end";
true
}
}
};

public type CallReq = TestTypes.CallReq;
public type CallRes = TestTypes.Res;
public type CallLog = [(CallReq, CallRes)];

var callLog : Buffer.Buffer<(CallReq, CallRes)> = Buffer.Buffer(0);

public func getFullLog () : async CallLog {
callLog.toArray()
};

// Bonus:
// For testing in an open, interactive world:
// Use this to add other tests not-yet expressed above!
Expand Down

0 comments on commit 68a7c00

Please sign in to comment.