-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_demo.sh
More file actions
executable file
·475 lines (388 loc) · 17 KB
/
Copy pathrun_demo.sh
File metadata and controls
executable file
·475 lines (388 loc) · 17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
#!/usr/bin/env bash
#
# run_demo.sh -- End-to-end demonstration of the DonationTracker contract.
#
# Runs two scenarios against a local Hardhat node:
# 1. Clean Water Initiative: full campaign lifecycle
# 2. Failed Campaign: refund after missed goal and expired deadline
#
# Prerequisites:
# - Ethereum Local Testing Starter Pack running (./eth.sh start)
# - bash, curl, jq
# - .env file configured (copy from .env.example)
#
# Usage:
# cp .env.example .env
# ./run_demo.sh
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DEMO_DIR="${SCRIPT_DIR}/demo"
CONTRACT_DIR="${SCRIPT_DIR}/contracts"
# Load environment
if [ -f "${SCRIPT_DIR}/.env" ]; then
set -a
source "${SCRIPT_DIR}/.env"
set +a
fi
# Source shared helpers
source "${DEMO_DIR}/lib.sh"
ETH_STARTER_PACK_DIR="${ETH_STARTER_PACK_DIR:-${SCRIPT_DIR}/../Ethereum-Local-Testing-Starter-Pack}"
if [ ! -f "${ETH_STARTER_PACK_DIR}/eth.sh" ]; then
error "Starter pack not found at ${ETH_STARTER_PACK_DIR}"
error "Set ETH_STARTER_PACK_DIR in .env to the correct path."
exit 1
fi
DATA_FILE="${DEMO_DIR}/sample_data.json"
# ============================================================================
# Step 0: Create accounts, compile, and deploy
# ============================================================================
section "Setup: Creating Accounts"
step "Creating funded accounts via starter pack..."
CHARITY=$(create_funded_account "charity" 100)
info "Charity:" "$CHARITY"
DONOR1=$(create_funded_account "donor1" 100)
info "Donor 1:" "$DONOR1"
DONOR2=$(create_funded_account "donor2" 100)
info "Donor 2:" "$DONOR2"
DONOR3=$(create_funded_account "donor3" 100)
info "Donor 3:" "$DONOR3"
RECIP1=$(create_funded_account "recipient1" 0)
info "Recipient 1:" "$RECIP1"
RECIP2=$(create_funded_account "recipient2" 0)
info "Recipient 2:" "$RECIP2"
# Set EVM_ACCOUNT for lib.sh functions (deploy, send_tx default sender)
EVM_ACCOUNT="$CHARITY"
echo ""
section "Setup: Compiling and Deploying Contract"
step "Compiling DonationTracker.sol via starter pack hardhat container..."
set +e
EVM_BYTECODE=$(docker compose -f "${ETH_STARTER_PACK_DIR}/compose.yml" run --rm \
-v "${CONTRACT_DIR}:/tmp/contract" \
hardhat sh -c '
npm install --no-save solc@0.8.28 >/dev/null 2>&1 &&
node -e "
const solc = require(\"solc\");
const fs = require(\"fs\");
const source = fs.readFileSync(\"/tmp/contract/DonationTracker.sol\", \"utf8\");
const input = JSON.stringify({
language: \"Solidity\",
sources: { \"DonationTracker.sol\": { content: source } },
settings: { outputSelection: { \"*\": { \"*\": [\"evm.bytecode.object\"] } } }
});
const output = JSON.parse(solc.compile(input));
if (output.errors) {
const errs = output.errors.filter(e => e.severity === \"error\");
if (errs.length > 0) {
console.error(JSON.stringify(errs, null, 2));
process.exit(1);
}
}
const bytecode = output.contracts[\"DonationTracker.sol\"][\"DonationTracker\"].evm.bytecode.object;
process.stdout.write(bytecode);
"
')
COMPILE_EXIT=$?
set -e
if [ $COMPILE_EXIT -ne 0 ] || [ -z "$EVM_BYTECODE" ]; then
error "Failed to compile DonationTracker.sol (exit code ${COMPILE_EXIT})"
error "Make sure the Ethereum Local Testing Starter Pack is available"
error "and ETH_STARTER_PACK_DIR is set correctly in .env"
exit 1
fi
# Strip any control characters or whitespace injected by Docker
EVM_BYTECODE=$(echo "$EVM_BYTECODE" | tr -d '[:cntrl:][:space:]')
echo ""
step "Deploying DonationTracker..."
set +e
CONTRACT=$(eth_deploy "0x${EVM_BYTECODE}")
DEPLOY_EXIT=$?
set -e
if [ $DEPLOY_EXIT -ne 0 ] || [ -z "$CONTRACT" ]; then
error "Contract deployment failed (exit code ${DEPLOY_EXIT})"
error "Check that the Ethereum network is running at ${EVM_RPC_URL}"
exit 1
fi
info "Contract:" "$CONTRACT"
echo ""
# ============================================================================
# Pre-compute hashes from sample data
# ============================================================================
# Campaign description
CAMPAIGN_DESC=$(jq -r '.scenarios.clean_water.description' "$DATA_FILE")
DESC_HASH=$(sha256_hash "$CAMPAIGN_DESC")
# Goal and deadline
GOAL_WEI=$(jq -r '.scenarios.clean_water.goal_wei' "$DATA_FILE")
GOAL_ETH=$(jq -r '.scenarios.clean_water.goal_eth' "$DATA_FILE")
CURRENT_TS=$(get_block_timestamp)
DEADLINE_OFFSET=$(jq -r '.scenarios.clean_water.deadline_offset_seconds' "$DATA_FILE")
DEADLINE=$(( CURRENT_TS + DEADLINE_OFFSET ))
# Donor message hash
DONOR1_MSG=$(jq -r '.scenarios.clean_water.donations[0].message' "$DATA_FILE")
DONOR1_MSG_HASH=$(sha256_hash "$DONOR1_MSG")
# Allocation hashes
ALLOC1_PURPOSE=$(jq -r '.scenarios.clean_water.allocations[0].purpose' "$DATA_FILE")
ALLOC1_EVIDENCE=$(jq -r '.scenarios.clean_water.allocations[0].evidence' "$DATA_FILE")
ALLOC1_PURPOSE_HASH=$(sha256_hash "$ALLOC1_PURPOSE")
ALLOC1_EVIDENCE_HASH=$(sha256_hash "$ALLOC1_EVIDENCE")
ALLOC1_ETH=$(jq -r '.scenarios.clean_water.allocations[0].amount_eth' "$DATA_FILE")
ALLOC1_WEI=$(jq -r '.scenarios.clean_water.allocations[0].amount_wei' "$DATA_FILE")
ALLOC1_LABEL=$(jq -r '.scenarios.clean_water.allocations[0].label' "$DATA_FILE")
ALLOC2_PURPOSE=$(jq -r '.scenarios.clean_water.allocations[1].purpose' "$DATA_FILE")
ALLOC2_EVIDENCE=$(jq -r '.scenarios.clean_water.allocations[1].evidence' "$DATA_FILE")
ALLOC2_PURPOSE_HASH=$(sha256_hash "$ALLOC2_PURPOSE")
ALLOC2_EVIDENCE_HASH=$(sha256_hash "$ALLOC2_EVIDENCE")
ALLOC2_ETH=$(jq -r '.scenarios.clean_water.allocations[1].amount_eth' "$DATA_FILE")
ALLOC2_WEI=$(jq -r '.scenarios.clean_water.allocations[1].amount_wei' "$DATA_FILE")
ALLOC2_LABEL=$(jq -r '.scenarios.clean_water.allocations[1].label' "$DATA_FILE")
# Disbursement hashes
DISB1_EVIDENCE=$(jq -r '.scenarios.clean_water.disbursements[0].evidence' "$DATA_FILE")
DISB1_EVIDENCE_HASH=$(sha256_hash "$DISB1_EVIDENCE")
DISB1_ETH=$(jq -r '.scenarios.clean_water.disbursements[0].amount_eth' "$DATA_FILE")
DISB1_WEI=$(jq -r '.scenarios.clean_water.disbursements[0].amount_wei' "$DATA_FILE")
DISB1_LABEL=$(jq -r '.scenarios.clean_water.disbursements[0].label' "$DATA_FILE")
DISB2_EVIDENCE=$(jq -r '.scenarios.clean_water.disbursements[1].evidence' "$DATA_FILE")
DISB2_EVIDENCE_HASH=$(sha256_hash "$DISB2_EVIDENCE")
DISB2_ETH=$(jq -r '.scenarios.clean_water.disbursements[1].amount_eth' "$DATA_FILE")
DISB2_WEI=$(jq -r '.scenarios.clean_water.disbursements[1].amount_wei' "$DATA_FILE")
DISB2_LABEL=$(jq -r '.scenarios.clean_water.disbursements[1].label' "$DATA_FILE")
# Zero hash for empty message
ZERO_HASH="0x0000000000000000000000000000000000000000000000000000000000000000"
# ============================================================================
# Scenario 1: Clean Water Initiative
# ============================================================================
section "Scenario 1: Clean Water Initiative"
# -- Step 1: Create campaign --
step "Step 1: Creating campaign..."
info "Description:" "\"${CAMPAIGN_DESC}\""
info "Description hash:" "${DESC_HASH}"
info "Goal:" "${GOAL_ETH} ETH"
info "Deadline:" "${DEADLINE} ($(( DEADLINE_OFFSET / 86400 )) days from now)"
echo ""
CALLDATA="0x${SEL_CREATE_CAMPAIGN}$(strip_0x "$DESC_HASH")$(uint256 "$GOAL_WEI")$(uint256 "$DEADLINE")"
TX=$(eth_send_tx "$CONTRACT" "$CALLDATA")
GAS=$(eth_get_receipt "$TX")
info "Campaign ID:" "0"
success "Created. Gas used: ${GAS}"
echo ""
# -- Step 2: Donor 1 --
step "Step 2: Donor 1 contributes 2.0 ETH..."
info "Donor:" "${DONOR1}"
info "Amount:" "2.0 ETH"
info "Message:" "\"${DONOR1_MSG}\""
info "Message hash:" "${DONOR1_MSG_HASH}"
echo ""
CALLDATA="0x${SEL_DONATE}$(uint256 0)$(strip_0x "$DONOR1_MSG_HASH")"
TX=$(eth_send_tx_from "$DONOR1" "$CONTRACT" "$CALLDATA" "$(wei_to_hex 2000000000000000000)")
GAS=$(eth_get_receipt "$TX")
success "Donated. Gas used: ${GAS}"
echo ""
# -- Step 3: Donor 2 --
step "Step 3: Donor 2 contributes 1.5 ETH..."
info "Donor:" "${DONOR2}"
info "Amount:" "1.5 ETH"
echo ""
CALLDATA="0x${SEL_DONATE}$(uint256 0)$(strip_0x "$ZERO_HASH")"
TX=$(eth_send_tx_from "$DONOR2" "$CONTRACT" "$CALLDATA" "$(wei_to_hex 1500000000000000000)")
GAS=$(eth_get_receipt "$TX")
success "Donated. Gas used: ${GAS}"
echo ""
# -- Step 4: Donor 3 --
step "Step 4: Donor 3 contributes 2.0 ETH..."
info "Donor:" "${DONOR3}"
info "Amount:" "2.0 ETH"
echo ""
CALLDATA="0x${SEL_DONATE}$(uint256 0)$(strip_0x "$ZERO_HASH")"
TX=$(eth_send_tx_from "$DONOR3" "$CONTRACT" "$CALLDATA" "$(wei_to_hex 2000000000000000000)")
GAS=$(eth_get_receipt "$TX")
success "Donated. Gas used: ${GAS}"
echo ""
# -- Step 5: Query campaign --
step "Step 5: Query campaign status..."
RESULT=$(eth_call "$CONTRACT" "0x${SEL_GET_CAMPAIGN}$(uint256 0)")
RAW=$(strip_0x "$RESULT")
CREATOR=$(decode_address "${RAW:0:64}")
RET_GOAL=$(decode_uint256 "${RAW:128:64}")
RET_DEADLINE=$(decode_uint256 "${RAW:192:64}")
RET_DONATED=$(decode_uint256 "${RAW:256:64}")
RET_ALLOCATED=$(decode_uint256 "${RAW:320:64}")
RET_DISBURSED=$(decode_uint256 "${RAW:384:64}")
RET_REFUNDED=$(decode_uint256 "${RAW:448:64}")
RET_STATUS=$(decode_uint256 "${RAW:512:64}")
STATUS_LABEL="Active"
if [ "$RET_STATUS" = "1" ]; then STATUS_LABEL="Finalized"; fi
BAL_RESULT=$(eth_call "$CONTRACT" "0x${SEL_GET_BALANCE}$(uint256 0)")
BALANCE=$(decode_uint256 "$(strip_0x "$BAL_RESULT")")
info "Campaign ID:" "0"
info "Creator:" "${CREATOR}"
info "Goal:" "$(wei_to_eth "$RET_GOAL") ETH"
info "Total donated:" "$(wei_to_eth "$RET_DONATED") ETH"
info "Total allocated:" "$(wei_to_eth "$RET_ALLOCATED") ETH"
info "Total disbursed:" "$(wei_to_eth "$RET_DISBURSED") ETH"
info "Status:" "${STATUS_LABEL}"
info "Balance held:" "$(wei_to_eth "$BALANCE") ETH"
echo ""
# -- Step 6: Allocate to water purification equipment --
step "Step 6: Allocate ${ALLOC1_ETH} ETH to ${ALLOC1_LABEL}..."
info "Purpose:" "\"${ALLOC1_PURPOSE}\""
info "Purpose hash:" "${ALLOC1_PURPOSE_HASH}"
info "Evidence:" "${ALLOC1_EVIDENCE}"
info "Evidence hash:" "${ALLOC1_EVIDENCE_HASH}"
echo ""
CALLDATA="0x${SEL_ALLOCATE}$(uint256 0)$(uint256 "$ALLOC1_WEI")$(strip_0x "$ALLOC1_PURPOSE_HASH")$(strip_0x "$ALLOC1_EVIDENCE_HASH")"
TX=$(eth_send_tx "$CONTRACT" "$CALLDATA")
GAS=$(eth_get_receipt "$TX")
success "Allocated. Gas used: ${GAS}"
echo ""
# -- Step 7: Allocate to distribution logistics --
step "Step 7: Allocate ${ALLOC2_ETH} ETH to ${ALLOC2_LABEL}..."
info "Purpose:" "\"${ALLOC2_PURPOSE}\""
info "Purpose hash:" "${ALLOC2_PURPOSE_HASH}"
info "Evidence:" "${ALLOC2_EVIDENCE}"
info "Evidence hash:" "${ALLOC2_EVIDENCE_HASH}"
echo ""
CALLDATA="0x${SEL_ALLOCATE}$(uint256 0)$(uint256 "$ALLOC2_WEI")$(strip_0x "$ALLOC2_PURPOSE_HASH")$(strip_0x "$ALLOC2_EVIDENCE_HASH")"
TX=$(eth_send_tx "$CONTRACT" "$CALLDATA")
GAS=$(eth_get_receipt "$TX")
success "Allocated. Gas used: ${GAS}"
echo ""
# -- Step 8: Query allocations --
step "Step 8: Query allocations..."
ALLOC_RESULT=$(eth_call "$CONTRACT" "0x${SEL_GET_ALLOCATIONS}$(uint256 0)")
info "Allocations:" "retrieved ($(( (${#ALLOC_RESULT} - 2) / 2 )) bytes of ABI data)"
echo ""
# -- Step 9: Disburse to WaterTech Supplies --
step "Step 9: Disburse ${DISB1_ETH} ETH to ${DISB1_LABEL}..."
info "Recipient:" "${RECIP1}"
info "Amount:" "${DISB1_ETH} ETH"
info "Allocation:" "0 (${ALLOC1_LABEL})"
info "Evidence:" "${DISB1_EVIDENCE}"
info "Evidence hash:" "${DISB1_EVIDENCE_HASH}"
echo ""
CALLDATA="0x${SEL_DISBURSE}$(uint256 0)$(encode_address "$RECIP1")$(uint256 "$DISB1_WEI")$(uint256 0)$(strip_0x "$DISB1_EVIDENCE_HASH")"
TX=$(eth_send_tx "$CONTRACT" "$CALLDATA")
GAS=$(eth_get_receipt "$TX")
success "Disbursed. Gas used: ${GAS}"
echo ""
# -- Step 10: Disburse to Regional Transport --
step "Step 10: Disburse ${DISB2_ETH} ETH to ${DISB2_LABEL}..."
info "Recipient:" "${RECIP2}"
info "Amount:" "${DISB2_ETH} ETH"
info "Allocation:" "1 (${ALLOC2_LABEL})"
info "Evidence:" "${DISB2_EVIDENCE}"
info "Evidence hash:" "${DISB2_EVIDENCE_HASH}"
echo ""
CALLDATA="0x${SEL_DISBURSE}$(uint256 0)$(encode_address "$RECIP2")$(uint256 "$DISB2_WEI")$(uint256 1)$(strip_0x "$DISB2_EVIDENCE_HASH")"
TX=$(eth_send_tx "$CONTRACT" "$CALLDATA")
GAS=$(eth_get_receipt "$TX")
success "Disbursed. Gas used: ${GAS}"
echo ""
# -- Step 11: Finalize --
step "Step 11: Finalize campaign..."
TX=$(eth_send_tx "$CONTRACT" "0x${SEL_FINALIZE}$(uint256 0)")
GAS=$(eth_get_receipt "$TX")
success "Finalized. Gas used: ${GAS}"
echo ""
# -- Step 12: Full audit trail --
step "Step 12: Full audit trail query..."
RESULT=$(eth_call "$CONTRACT" "0x${SEL_GET_CAMPAIGN}$(uint256 0)")
RAW=$(strip_0x "$RESULT")
RET_DONATED=$(decode_uint256 "${RAW:256:64}")
RET_ALLOCATED=$(decode_uint256 "${RAW:320:64}")
RET_DISBURSED=$(decode_uint256 "${RAW:384:64}")
RET_REFUNDED=$(decode_uint256 "${RAW:448:64}")
RET_STATUS=$(decode_uint256 "${RAW:512:64}")
STATUS_LABEL="Active"
if [ "$RET_STATUS" = "1" ]; then STATUS_LABEL="Finalized"; fi
BAL_RESULT=$(eth_call "$CONTRACT" "0x${SEL_GET_BALANCE}$(uint256 0)")
BALANCE=$(decode_uint256 "$(strip_0x "$BAL_RESULT")")
info "Campaign ID:" "0"
info "Creator:" "${CHARITY}"
info "Goal:" "${GOAL_ETH} ETH"
info "Total donated:" "$(wei_to_eth "$RET_DONATED") ETH"
info "Total allocated:" "$(wei_to_eth "$RET_ALLOCATED") ETH"
info "Total disbursed:" "$(wei_to_eth "$RET_DISBURSED") ETH"
info "Remaining balance:" "$(wei_to_eth "$BALANCE") ETH (unallocated surplus)"
info "Status:" "${STATUS_LABEL}"
echo ""
echo " Flow summary:"
echo " Donated: $(wei_to_eth "$RET_DONATED") ETH (3 donors)"
echo " Allocated: $(wei_to_eth "$RET_ALLOCATED") ETH (2 purposes)"
echo " Disbursed: $(wei_to_eth "$RET_DISBURSED") ETH (2 recipients)"
echo " Remaining: $(wei_to_eth "$BALANCE") ETH (held in contract)"
section "Scenario 1: COMPLETE"
# ============================================================================
# Scenario 2: Failed Campaign with Refund
# ============================================================================
section "Scenario 2: Failed Campaign (Refund)"
# Campaign 2: high goal, short deadline
CAMP2_DESC=$(jq -r '.scenarios.failed_campaign.description' "$DATA_FILE")
CAMP2_DESC_HASH=$(sha256_hash "$CAMP2_DESC")
CAMP2_GOAL_WEI=$(jq -r '.scenarios.failed_campaign.goal_wei' "$DATA_FILE")
CAMP2_GOAL_ETH=$(jq -r '.scenarios.failed_campaign.goal_eth' "$DATA_FILE")
CAMP2_DEADLINE_OFFSET=$(jq -r '.scenarios.failed_campaign.deadline_offset_seconds' "$DATA_FILE")
CAMP2_TS=$(get_block_timestamp)
CAMP2_DEADLINE=$(( CAMP2_TS + CAMP2_DEADLINE_OFFSET ))
# -- Step 1: Create --
step "Step 1: Creating campaign with high goal..."
info "Description:" "\"${CAMP2_DESC}\""
info "Goal:" "${CAMP2_GOAL_ETH} ETH"
info "Deadline:" "${CAMP2_DEADLINE} (short deadline for demo)"
info "Campaign ID:" "1"
echo ""
CALLDATA="0x${SEL_CREATE_CAMPAIGN}$(strip_0x "$CAMP2_DESC_HASH")$(uint256 "$CAMP2_GOAL_WEI")$(uint256 "$CAMP2_DEADLINE")"
TX=$(eth_send_tx "$CONTRACT" "$CALLDATA")
GAS=$(eth_get_receipt "$TX")
success "Created. Gas used: ${GAS}"
echo ""
# -- Step 2: Donor contributes --
CAMP2_AMOUNT_WEI=$(jq -r '.scenarios.failed_campaign.donations[0].amount_wei' "$DATA_FILE")
CAMP2_AMOUNT_ETH=$(jq -r '.scenarios.failed_campaign.donations[0].amount_eth' "$DATA_FILE")
step "Step 2: Donor 1 contributes ${CAMP2_AMOUNT_ETH} ETH..."
info "Donor:" "${DONOR1}"
info "Amount:" "${CAMP2_AMOUNT_ETH} ETH"
echo ""
CALLDATA="0x${SEL_DONATE}$(uint256 1)$(strip_0x "$ZERO_HASH")"
TX=$(eth_send_tx_from "$DONOR1" "$CONTRACT" "$CALLDATA" "$(wei_to_hex "$CAMP2_AMOUNT_WEI")")
GAS=$(eth_get_receipt "$TX")
success "Donated. Gas used: ${GAS}"
echo ""
# -- Step 3: Advance time --
step "Step 3: Advance time past deadline..."
ADVANCE_SECS=$(( CAMP2_DEADLINE_OFFSET + 60 ))
info "Using evm_increaseTime to advance ${ADVANCE_SECS} seconds..."
evm_increase_time "$ADVANCE_SECS"
evm_mine
NEW_TS=$(get_block_timestamp)
info "Mining a block with evm_mine..."
success "Time advanced. Block timestamp is now ${NEW_TS} (past deadline ${CAMP2_DEADLINE})."
echo ""
# -- Step 4: Refund --
step "Step 4: Attempt refund (goal not met, deadline passed)..."
info "Donor:" "${DONOR1}"
info "Refund amount:" "${CAMP2_AMOUNT_ETH} ETH"
echo ""
TX=$(eth_send_tx_from "$DONOR1" "$CONTRACT" "0x${SEL_REFUND}$(uint256 1)")
GAS=$(eth_get_receipt "$TX")
success "Refunded. Gas used: ${GAS}"
echo ""
# -- Step 5: Verify --
step "Step 5: Verify campaign balance..."
BAL_RESULT=$(eth_call "$CONTRACT" "0x${SEL_GET_BALANCE}$(uint256 1)")
BALANCE=$(decode_uint256 "$(strip_0x "$BAL_RESULT")")
info "Campaign balance:" "$(wei_to_eth "$BALANCE") ETH"
success "Donor successfully refunded."
section "Scenario 2: COMPLETE (Refund successful)"
# ============================================================================
# Summary
# ============================================================================
section "Summary"
echo "Scenario 1 (Clean Water Initiative):"
echo " Campaign created, funded by 3 donors (5.5 ETH total)"
echo " Allocated to 2 purposes (5.0 ETH)"
echo " Disbursed to 2 recipients (5.0 ETH)"
echo " Full audit trail queryable at zero gas cost"
echo ""
echo "Scenario 2 (Failed Campaign):"
echo " Campaign created with unmet goal"
echo " Time advanced past deadline"
echo " Donor successfully refunded"