Skip to content

Commit

Permalink
Add tests for log allowed viewer list, with the tests disabled for now.
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-dfinity committed Sep 23, 2024
1 parent b0e2155 commit 1286e76
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
32 changes: 32 additions & 0 deletions e2e/tests-dfx/create.bash
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,35 @@ teardown() {
assert_contains 'Freezing threshold: 2_592_000'
assert_contains 'Log visibility: controllers'
}

@test "create with log allowed viewer list" {
skip

# Create two identities
assert_command dfx identity new --storage-mode plaintext alice
assert_command dfx identity new --storage-mode plaintext bob
ALICE_PRINCIPAL=$(dfx identity get-principal --identity alice)
BOB_PRINCIPAL=$(dfx identity get-principal --identity bob)

jq '.canisters.e2e_project_backend.initialization_values={
"compute_allocation": 5,
"freezing_threshold": "7days",
"memory_allocation": "2 GiB",
"reserved_cycles_limit": 1000000000000,
"wasm_memory_limit": "1 GiB",
"log_visibility": {
"allowed_viewers" :
['\""$ALICE_PRINCIPAL"\"', '\""$BOB_PRINCIPAL"\"']
}
}' dfx.json | sponge dfx.json
dfx_start
assert_command dfx deploy e2e_project_backend --no-wallet
assert_command dfx canister status e2e_project_backend
assert_contains 'Memory allocation: 2_147_483_648'
assert_contains 'Compute allocation: 5'
assert_contains 'Reserved cycles limit: 1_000_000_000_000'
assert_contains 'Wasm memory limit: 1_073_741_824'
assert_contains 'Freezing threshold: 604_800'
assert_contains "${ALICE_PRINCIPAL}"
assert_contains "${BOB_PRINCIPAL}"
}
76 changes: 76 additions & 0 deletions e2e/tests-dfx/update_settings.bash
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,89 @@ teardown() {
dfx_start
assert_command dfx deploy e2e_project_backend
assert_command dfx canister status e2e_project_backend

# Test against a single canister.
assert_contains "Log visibility: controllers"
assert_command dfx canister update-settings e2e_project_backend --log-visibility public
assert_command dfx canister status e2e_project_backend
assert_contains "Log visibility: public"
assert_command dfx canister update-settings e2e_project_backend --log-visibility controllers
assert_command dfx canister status e2e_project_backend
assert_contains "Log visibility: controllers"

# Test --all code path.
assert_command dfx canister update-settings --log-visibility public --all
assert_command dfx canister status e2e_project_backend
assert_contains "Log visibility: public"
assert_command dfx canister update-settings --log-visibility controllers --all
assert_command dfx canister status e2e_project_backend
assert_contains "Log visibility: controllers"
}

@test "update log allowed viewer list" {
skip

# Create two identities
assert_command dfx identity new --storage-mode plaintext alice
assert_command dfx identity new --storage-mode plaintext bob
ALICE_PRINCIPAL=$(dfx identity get-principal --identity alice)
BOB_PRINCIPAL=$(dfx identity get-principal --identity bob)

dfx_new
dfx_start
assert_command dfx deploy e2e_project_backend
assert_command dfx canister status e2e_project_backend
assert_contains "Log visibility: controllers"

# Test against a single canister.
assert_command dfx canister update-settings --add-log-viewer="${ALICE_PRINCIPAL}" e2e_project_backend
assert_command dfx canister status e2e_project_backend
assert_contains "${ALICE_PRINCIPAL}"

assert_command dfx canister update-settings --add-log-viewer="${BOB_PRINCIPAL}" --remove-log-viewer="${ALICE_PRINCIPAL}" e2e_project_backend
assert_command dfx canister status e2e_project_backend
assert_contains "${BOB_PRINCIPAL}"
assert_not_contains "${ALICE_PRINCIPAL}"

assert_command dfx canister update-settings --set-log-viewer="${ALICE_PRINCIPAL}" e2e_project_backend
assert_command dfx canister status e2e_project_backend
assert_contains "${ALICE_PRINCIPAL}"
assert_not_contains "${BOB_PRINCIPAL}"

assert_command dfx canister update-settings --remove-log-viewer="${ALICE_PRINCIPAL}" e2e_project_backend
assert_command dfx canister status e2e_project_backend
assert_contains "Allowed List is empty"

assert_command dfx canister update-settings --add-log-viewer="${BOB_PRINCIPAL}" --add-log-viewer="${ALICE_PRINCIPAL}" e2e_project_backend
assert_command dfx canister status e2e_project_backend
assert_contains "${ALICE_PRINCIPAL}"
assert_contains "${BOB_PRINCIPAL}"

assert_command dfx canister update-settings --remove-log-viewer="${ALICE_PRINCIPAL}" --remove-log-viewer="${BOB_PRINCIPAL}" e2e_project_backend
assert_command dfx canister status e2e_project_backend
assert_contains "Allowed List is empty"

assert_command dfx canister update-settings --set-log-viewer="${BOB_PRINCIPAL}" --set-log-viewer="${ALICE_PRINCIPAL}" e2e_project_backend
assert_command dfx canister status e2e_project_backend
assert_contains "${ALICE_PRINCIPAL}"
assert_contains "${BOB_PRINCIPAL}"

assert_command dfx canister update-settings --log-visibility controllers e2e_project_backend
assert_command dfx canister status e2e_project_backend
assert_contains "Log visibility: controllers"

# Test --all code path.
assert_command dfx canister update-settings --add-log-viewer="${ALICE_PRINCIPAL}" --all
assert_command dfx canister status e2e_project_backend
assert_contains "${ALICE_PRINCIPAL}"

assert_command dfx canister update-settings --remove-log-viewer="${ALICE_PRINCIPAL}" --all
assert_command dfx canister status e2e_project_backend
assert_contains "Allowed List is empty"

assert_command dfx canister update-settings --set-log-viewer="${ALICE_PRINCIPAL}" --all
assert_command dfx canister status e2e_project_backend
assert_contains "${ALICE_PRINCIPAL}"
}

@test "set controller" {
Expand Down

0 comments on commit 1286e76

Please sign in to comment.