Skip to content

Commit

Permalink
rewritten with jq, some more coverage on txn group
Browse files Browse the repository at this point in the history
  • Loading branch information
ahangsu committed Mar 20, 2023
1 parent c454f2c commit f84587a
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions test/scripts/e2e_subs/e2e-app-simulate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,33 @@ gcmd="goal -w ${WALLET}"

ACCOUNT=$(${gcmd} account list|awk '{ print $3 }')

CONST_TRUE="true"
CONST_FALSE="false"

${gcmd} clerk send -a 10000 -f ${ACCOUNT} -t ${ACCOUNT} -o pay1.tx
${gcmd} clerk send -a 10000 -f ${ACCOUNT} -t ${ACCOUNT} -o pay2.tx

cat pay1.tx pay2.tx | ${gcmd} clerk group -i - -o grouped.tx

# We first test transaction group simulation WITHOUT signatures
RES=$(${gcmd} clerk simulate -t grouped.tx | jq '."would-succeed"')

if [[ $RES != $CONST_FALSE ]]; then
date '+app-simulate-test FAIL the simulation transaction group without signatures should not succeed %Y%m%d_%H%M%S'
false
fi

# We then test transaction group simulation WITH signatures
${gcmd} clerk split -i grouped.tx -o grouped.tx

${gcmd} clerk sign -i grouped-0.tx -o grouped-0.stx
${gcmd} clerk sign -i grouped-1.tx -o grouped-1.stx

cat grouped-0.stx grouped-1.stx > grouped.stx

RES=$(${gcmd} clerk simulate -t grouped.stx)
EXPSUCCESS='"would-succeed": true'
RES=$(${gcmd} clerk simulate -t grouped.stx | jq '."would-succeed"')

if [[ $RES != *"${EXPSUCCESS}"* ]]; then
if [[ $RES != $CONST_TRUE ]]; then
date '+app-simulate-test FAIL should pass to simulate self pay transaction group %Y%m%d_%H%M%S'
false
fi
Expand Down Expand Up @@ -59,28 +71,24 @@ ${gcmd} app method --method "empty()void" --app-id $APPID --from $ACCOUNT 2>&1 -
# SIMULATE without a signature first
RES=$(${gcmd} clerk simulate -t empty.tx)

EXPFAIL='"would-succeed": false'

FAIL_REASON_SIG_MISSING='"missing-signature": true'

# confirm that without signature, the simulation should fail
if [[ $RES != *"${EXPFAIL}"* ]]; then
if [[ $(echo "$RES" | jq '."would-succeed"') != $CONST_FALSE ]]; then
date '+app-simulate-test FAIL the simulation call to empty()void without signature should not succeed %Y%m%d_%H%M%S'
false
fi

# check again the simulation failing reason
if [[ $RES != *"${FAIL_REASON_SIG_MISSING}"* ]]; then
if [[ $(echo "$RES" | jq '."txn-groups"[0]."txn-results"[0]."missing-signature"') != $CONST_TRUE ]]; then
date '+app-simulate-test FAIL the simulation call to empty()void without signature should fail with missing-signature %Y%m%d_%H%M%S'
false
fi

# SIMULATE with a signature
${gcmd} clerk sign -i empty.tx -o empty.stx
RES=$(${gcmd} clerk simulate -t empty.stx)
RES=$(${gcmd} clerk simulate -t empty.stx | jq '."would-succeed"')

# with signature, simulation app-call should succeed
if [[ $RES != *"${EXPSUCCESS}"* ]]; then
if [[ $RES != $CONST_TRUE ]]; then
date '+app-simulate-test FAIL the simulation call to empty()void should succeed %Y%m%d_%H%M%S'
false
fi

0 comments on commit f84587a

Please sign in to comment.