From f244a5cd264ebaf55865a846177522f0b6251bca Mon Sep 17 00:00:00 2001 From: nullun Date: Mon, 25 Nov 2024 14:03:50 +0000 Subject: [PATCH 1/4] Set logic sig address as sender if sender is not provided --- cmd/goal/clerk.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/goal/clerk.go b/cmd/goal/clerk.go index c1b534a722..10297dcadd 100644 --- a/cmd/goal/clerk.go +++ b/cmd/goal/clerk.go @@ -383,7 +383,11 @@ var sendCmd = &cobra.Command{ if program != nil { ph := logic.HashProgram(program) pha := basics.Address(ph) - fromAddressResolved = pha.String() + if account == "" { + fromAddressResolved = pha.String() + } else { + fromAddressResolved = accountList.getAddressByName(account) + } programArgs = getProgramArgs() } else { // Check if from was specified, else use default From 3ef09ec1b175be9d435db98dbfa06a406f9e4667 Mon Sep 17 00:00:00 2001 From: nullun Date: Mon, 25 Nov 2024 14:07:27 +0000 Subject: [PATCH 2/4] Use AuthAddr if set for logic sig transactions --- cmd/goal/clerk.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmd/goal/clerk.go b/cmd/goal/clerk.go index 10297dcadd..6625e96c9b 100644 --- a/cmd/goal/clerk.go +++ b/cmd/goal/clerk.go @@ -477,6 +477,13 @@ var sendCmd = &cobra.Command{ Args: programArgs, }, } + if signerAddress != "" { + var authAddr, err = basics.UnmarshalChecksumAddress(signerAddress) + if err != nil { + reportErrorf("Signer invalid (%s): %v", signerAddress, err) + } + stx.AuthAddr = basics.Address(authAddr) + } } else { signTx := sign || (outFilename == "") var authAddr basics.Address From ae2a84e526751e093b40b916de07852e3d9a0e42 Mon Sep 17 00:00:00 2001 From: nullun Date: Tue, 26 Nov 2024 13:13:03 +0000 Subject: [PATCH 3/4] Added LogicSig with Signer expect test --- .../cli/goal/expect/goalLogicSigTest.exp | 77 +++++++++++++++++++ test/scripts/e2e_subs/tealprogs/int1.teal | 2 + 2 files changed, 79 insertions(+) create mode 100644 test/e2e-go/cli/goal/expect/goalLogicSigTest.exp create mode 100644 test/scripts/e2e_subs/tealprogs/int1.teal diff --git a/test/e2e-go/cli/goal/expect/goalLogicSigTest.exp b/test/e2e-go/cli/goal/expect/goalLogicSigTest.exp new file mode 100644 index 0000000000..9d7a3eb393 --- /dev/null +++ b/test/e2e-go/cli/goal/expect/goalLogicSigTest.exp @@ -0,0 +1,77 @@ +#!/usr/bin/expect -f +set err 0 +log_user 1 + +if { [catch { + source goalExpectCommon.exp + set TEST_ALGO_DIR [lindex $argv 0] + set TEST_DATA_DIR [lindex $argv 1] + + puts "TEST_ALGO_DIR: $TEST_ALGO_DIR" + puts "TEST_DATA_DIR: $TEST_DATA_DIR" + + set TIME_STAMP [clock seconds] + + set TEST_ROOT_DIR $TEST_ALGO_DIR/root + set TEST_PRIMARY_NODE_DIR $TEST_ROOT_DIR/Primary/ + set NETWORK_NAME test_net_expect_$TIME_STAMP + set NETWORK_TEMPLATE "$TEST_DATA_DIR/nettemplates/TwoNodes50Each.json" + + # Create network + ::AlgorandGoal::CreateNetwork $NETWORK_NAME $NETWORK_TEMPLATE $TEST_ALGO_DIR $TEST_ROOT_DIR + + # Start network + ::AlgorandGoal::StartNetwork $NETWORK_NAME $NETWORK_TEMPLATE $TEST_ROOT_DIR + + set PRIMARY_NODE_ADDRESS [ ::AlgorandGoal::GetAlgodNetworkAddress $TEST_PRIMARY_NODE_DIR ] + puts "Primary Node Address: $PRIMARY_NODE_ADDRESS" + + set PRIMARY_WALLET_NAME unencrypted-default-wallet + + # Determine primary account + set PRIMARY_ACCOUNT_ADDRESS [::AlgorandGoal::GetHighestFundedAccountForWallet $PRIMARY_WALLET_NAME $TEST_PRIMARY_NODE_DIR] + + # rekey address to logic sig + set TEAL_PROGS_DIR "$TEST_DATA_DIR/../scripts/e2e_subs/tealprogs" + set TEAL_SOURCE "$TEST_ROOT_DIR/int1.teal" + exec cp "$TEAL_PROGS_DIR/int1.teal" $TEAL_SOURCE + set CONTRACT_ADDRESS [::AlgorandGoal::TealCompile $TEAL_SOURCE] + spawn goal clerk send -a 0 --fee 1000 -f $PRIMARY_ACCOUNT_ADDRESS -t $PRIMARY_ACCOUNT_ADDRESS --rekey-to $CONTRACT_ADDRESS -d $TEST_PRIMARY_NODE_DIR + expect { + timeout { close; ::AlgorandGoal::Abort "goal clerk send timeout" } + -re {Transaction ([A-Z0-9]+) expired before it could be included in a block} { + break; + close; + } + -re {Transaction ([A-Z0-9]+) kicked out of local node pool} { + # this is a legit possible case, so just keep iterating if we hit this one. + close; + } + -re {Couldn't broadcast tx with algod: HTTP 400 Bad Request: TransactionPool.Remember: txn dead: round ([0-9]+) outside of ([0-9]+)--([0-9]+)} { + # this is a legit possible case, so just keep iterating if we hit this one. + close; + } + eof { ::AlgorandGoal::CheckEOF "Failed to send a rekey transaction" } + } + + # create transaction with logic sig and signer + set TXN_WITH_SIGNER "$TEST_ROOT_DIR/txn_with_signer.txn" + spawn goal clerk send --from-program $TEAL_SOURCE --from $PRIMARY_ACCOUNT_ADDRESS --to $PRIMARY_ACCOUNT_ADDRESS --rekey-to $PRIMARY_ACCOUNT_ADDRESS -S $CONTRACT_ADDRESS --amount 1 -d $TEST_PRIMARY_NODE_DIR -o $TXN_WITH_SIGNER + expect { + timeout { ::AlgorandGoal::Abort "Timed out Teal transaction create" } + eof { catch wait result; if { [lindex $result 3] != 0 } { ::AlgorandGoal::Abort "failed to create teal transaction: error code [lindex $result 3]"} } + } + set RAW_TRANSACTION_ID [::AlgorandGoal::RawSend $TXN_WITH_SIGNER $TEST_PRIMARY_NODE_DIR] + puts "send transaction in $RAW_TRANSACTION_ID" + puts "TxnWithSigner Test Successful" + + # Shutdown the network + ::AlgorandGoal::StopNetwork $NETWORK_NAME $TEST_ROOT_DIR + + puts "Goal LogicSig with Signer Test Successful" + + exit 0 + +} EXCEPTION ] } { + ::AlgorandGoal::Abort "ERROR in goalLogicSigTest: $EXCEPTION" +} diff --git a/test/scripts/e2e_subs/tealprogs/int1.teal b/test/scripts/e2e_subs/tealprogs/int1.teal new file mode 100644 index 0000000000..0da948ae88 --- /dev/null +++ b/test/scripts/e2e_subs/tealprogs/int1.teal @@ -0,0 +1,2 @@ +#pragma version 10 +pushint 1 From 984f9d8c4f9cc54bbc6d553e9e08bb8c5de2c52d Mon Sep 17 00:00:00 2001 From: nullun Date: Tue, 26 Nov 2024 13:56:48 +0000 Subject: [PATCH 4/4] fix err shadowing --- cmd/goal/clerk.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmd/goal/clerk.go b/cmd/goal/clerk.go index 6625e96c9b..3c734a2e98 100644 --- a/cmd/goal/clerk.go +++ b/cmd/goal/clerk.go @@ -477,8 +477,9 @@ var sendCmd = &cobra.Command{ Args: programArgs, }, } + var authAddr basics.Address if signerAddress != "" { - var authAddr, err = basics.UnmarshalChecksumAddress(signerAddress) + authAddr, err = basics.UnmarshalChecksumAddress(signerAddress) if err != nil { reportErrorf("Signer invalid (%s): %v", signerAddress, err) }