Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Foreign* args to AddMethodCallParams #318

Merged
merged 4 commits into from
May 16, 2022
Merged
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
17 changes: 14 additions & 3 deletions future/atomicTransactionComposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ type AddMethodCallParams struct {
RekeyTo types.Address
// A transaction Signer that can authorize this application call from sender
Signer TransactionSigner
// Any foreign apps to be passed that aren't part of the method signature.
// If apps are provided here, the apps specified in the method args will appear after these
ForeignApps []uint64
// Any foreign assets to be passed that aren't part of the method signature
// If assets are provided here, the assets specified in the method args will appear after these
ForeignAssets []uint64
// Any foreign accounts to be passed that aren't part of the method signature
// If accounts are provided here, the accounts specified in the method args will appear after these
ForeignAccounts []string
}

// ExecuteResult contains the results of successfully calling the Execute method on an
Expand Down Expand Up @@ -305,9 +314,11 @@ func (atc *AtomicTransactionComposer) AddMethodCall(params AddMethodCallParams)
}
}

var foreignAccounts []string
var foreignApps []uint64
var foreignAssets []uint64
var (
foreignAccounts = params.ForeignAccounts[:]
foreignApps = params.ForeignApps[:]
foreignAssets = params.ForeignAssets[:]
)
refArgsResolved, err := populateMethodCallReferenceArgs(params.Sender.String(), params.AppID, refArgTypes, refArgValues, &foreignAccounts, &foreignApps, &foreignAssets)
if err != nil {
return err
Expand Down
44 changes: 44 additions & 0 deletions future/atomicTransactionComposer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,50 @@ func TestAddMethodCall(t *testing.T) {
require.Equal(t, atc.Count(), 1)
}

func TestAddMethodCallWithManualForeignArgs(t *testing.T) {
var atc AtomicTransactionComposer
account := crypto.GenerateAccount()
txSigner := BasicAccountTransactionSigner{Account: account}
methodSig := "add(application)uint32"

method, err := abi.MethodFromSignature(methodSig)
require.NoError(t, err)

addr, err := types.DecodeAddress("DN7MBMCL5JQ3PFUQS7TMX5AH4EEKOBJVDUF4TCV6WERATKFLQF4MQUPZTA")
require.NoError(t, err)

arg_addr_str := "E4VCHISDQPLIZWMALIGNPK2B2TERPDMR64MZJXE3UL75MUDXZMADX5OWXM"
arg_addr, err := types.DecodeAddress(arg_addr_str)
require.NoError(t, err)

err = atc.AddMethodCall(
AddMethodCallParams{
AppID: 4,
Method: method,
Sender: addr,
Signer: txSigner,
MethodArgs: []interface{}{2},
ForeignApps: []uint64{1},
ForeignAssets: []uint64{5},
ForeignAccounts: []string{arg_addr_str},
})
require.NoError(t, err)
require.Equal(t, atc.GetStatus(), BUILDING)
require.Equal(t, atc.Count(), 1)
txns, err := atc.BuildGroup()
require.NoError(t, err)

require.Equal(t, len(txns[0].Txn.ForeignApps), 2)
require.Equal(t, txns[0].Txn.ForeignApps[0], types.AppIndex(1))
require.Equal(t, txns[0].Txn.ForeignApps[1], types.AppIndex(2))

require.Equal(t, len(txns[0].Txn.ForeignAssets), 1)
require.Equal(t, txns[0].Txn.ForeignAssets[0], types.AssetIndex(5))

require.Equal(t, len(txns[0].Txn.Accounts), 1)
require.Equal(t, txns[0].Txn.Accounts[0], arg_addr)
}

func TestGatherSignatures(t *testing.T) {
var atc AtomicTransactionComposer
account := crypto.GenerateAccount()
Expand Down