Skip to content
Draft
Show file tree
Hide file tree
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
28 changes: 28 additions & 0 deletions .github/workflows/canister_logs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: canister_logs

on:
push:
branches: [master]
pull_request:
paths:
- motoko/canister_logs/**
- .github/workflows/canister_logs.yml

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
motoko-canister_logs:
runs-on: ubuntu-24.04
container: ghcr.io/dfinity/icp-dev-env-motoko:0.3.2
env:
ICP_CLI_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
- name: Deploy and test
working-directory: motoko/canister_logs
run: |
icp network start -d
icp deploy
make test
20 changes: 0 additions & 20 deletions motoko/canister_logs/.devcontainer/devcontainer.json

This file was deleted.

113 changes: 0 additions & 113 deletions motoko/canister_logs/BUILD.md

This file was deleted.

116 changes: 52 additions & 64 deletions motoko/canister_logs/Makefile
Original file line number Diff line number Diff line change
@@ -1,66 +1,54 @@
.PHONY: all
all: build

.PHONY: deploy
.SILENT: deploy
install:
dfx canister deploy CanisterLogs

.PHONY: test
.SILENT: test
test: deploy
# Test print via update call.
dfx canister call CanisterLogs print 'print via update'
dfx canister logs CanisterLogs \
| grep 'print via update' && echo 'PASS'

# Test print via replicated query call.
dfx canister call --update CanisterLogs print_query 'print via replicated query'
dfx canister logs CanisterLogs \
| grep 'print via replicated query' && echo 'PASS'

# Test print via non-replicated query call should NOT record the message.
dfx canister call --query CanisterLogs print_query 'print via non-replicated query'
! dfx canister logs CanisterLogs \
| grep 'print via non-replicated query' && echo 'PASS'

# Test trapped call is recorded in logs.
# Ignore failed dfx command output (so the test continues) and check the logs to contain the message.
- dfx canister call CanisterLogs trap 'trap via update'
dfx canister logs CanisterLogs \
| grep 'trap via update' && echo 'PASS'

# Test trap via replicated query call.
# Ignore failed dfx command output (so the test continues) and check the logs to contain the message.
- dfx canister call --update CanisterLogs trap_query 'trap via replicated query'
dfx canister logs CanisterLogs \
| grep 'trap via replicated query' && echo 'PASS'

# Test trap via non-replicated query call should NOT record the message.
# Ignore failed dfx command output (so the test continues) and check the logs to contain the message.
- dfx canister call --query CanisterLogs trap_query 'trap via non-replicated query'
! dfx canister logs CanisterLogs \
| grep 'trap via non-replicated query' && echo 'PASS'

# Test call to fail with memory out of bounds.
# Ignore failed dfx command output (so the test continues) and check the logs to contain the message.
- dfx canister call CanisterLogs memory_oob
dfx canister logs CanisterLogs \
| grep 'Region error: range out of bounds' && echo 'PASS'

# Test timer trap.
# The timer is setup to trap every 5 seconds, so this test has to be called
# at least 5 seconds after the start to record the trap log message.
sleep 5
dfx canister logs CanisterLogs \
| grep 'timer trap' && echo 'PASS'

# Test raw_rand.
dfx canister call CanisterLogs raw_rand
dfx canister logs CanisterLogs \
| grep 'ic.raw_rand() call succeeded' && echo 'PASS'

.PHONY: clean
.SILENT: clean
clean:
rm -fr .dfx
test:
@echo "=== Test 1/11: print via update call is recorded in logs ==="
@icp canister call backend print '("print via update")' && \
icp canister logs backend | grep -q 'print via update' && \
echo "PASS" || (echo "FAIL" && exit 1)

@echo "=== Test 2/11: print_query via replicated update call is recorded in logs ==="
@icp canister call backend print_query '("print via replicated query")' && \
icp canister logs backend | grep -q 'print via replicated query' && \
echo "PASS" || (echo "FAIL" && exit 1)

@echo "=== Test 3/11: trap via update call is recorded in logs ==="
@icp canister call backend trap '("trap via update")' 2>/dev/null || true
@icp canister logs backend | grep -q 'trap via update' && \
echo "PASS" || (echo "FAIL" && exit 1)

@echo "=== Test 4/11: trap logs 'right before trap' message before trapping ==="
@icp canister logs backend | grep -q 'right before trap' && \
echo "PASS" || (echo "FAIL" && exit 1)

@echo "=== Test 5/11: trap_query via update call is recorded in logs ==="
@icp canister call backend trap_query '("trap via replicated query")' 2>/dev/null || true
@icp canister logs backend | grep -q 'trap via replicated query' && \
echo "PASS" || (echo "FAIL" && exit 1)

@echo "=== Test 6/11: trap_query logs 'right before trap_query' before trapping ==="
@icp canister logs backend | grep -q 'right before trap_query' && \
echo "PASS" || (echo "FAIL" && exit 1)

@echo "=== Test 7/11: memory_oob trap is recorded in logs ==="
@icp canister call backend memory_oob '()' 2>/dev/null || true
@icp canister logs backend | grep -q 'Region error: range out of bounds' && \
echo "PASS" || (echo "FAIL" && exit 1)

@echo "=== Test 8/11: memory_oob logs 'right before memory out of bounds' ==="
@icp canister logs backend | grep -q 'right before memory out of bounds' && \
echo "PASS" || (echo "FAIL" && exit 1)

@echo "=== Test 9/11: timer trap is recorded in logs (waiting up to 10s) ==="
@sleep 10 && \
icp canister logs backend | grep -q 'timer trap' && \
echo "PASS" || (echo "FAIL" && exit 1)

@echo "=== Test 10/11: raw_rand returns a blob ==="
@result=$$(icp canister call backend raw_rand '()') && \
echo "$$result" && \
echo "$$result" | grep -q 'blob' && \
echo "PASS" || (echo "FAIL" && exit 1)

@echo "=== Test 11/11: raw_rand success is recorded in logs ==="
@icp canister logs backend | grep -q 'ic.raw_rand() call succeeded' && \
echo "PASS" || (echo "FAIL" && exit 1)
Loading
Loading