Skip to content

Commit

Permalink
PR comments, add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Warehime committed Jul 3, 2023
1 parent b9d52e9 commit 859238a
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 1 deletion.
2 changes: 1 addition & 1 deletion daemon/algod/api/client/restClient.go
Expand Up @@ -760,7 +760,7 @@ func (client RestClient) GetLedgerStateDeltaForTransactionGroup(id string) (resp
return
}

// GetTransactionGroupLedgerStateDeltasForRound retrieves the ledger state deltas for the txn groups in the specified by round
// GetTransactionGroupLedgerStateDeltasForRound retrieves the ledger state deltas for the txn groups in the specified round
func (client RestClient) GetTransactionGroupLedgerStateDeltasForRound(round uint64) (response model.TransactionGroupLedgerStateDeltasForRoundResponse, err error) {
err = client.get(&response, fmt.Sprintf("/v2/deltas/%d/txn/group", round), nil)
return
Expand Down
3 changes: 3 additions & 0 deletions test/e2e-go/features/devmode/devmode_test.go
Expand Up @@ -110,4 +110,7 @@ func TestTxnGroupDeltasDevMode(t *testing.T) {
groupDelta := roundResponse.Deltas[0]
require.Equal(t, 1, len(groupDelta.Ids))
require.Equal(t, groupDelta.Ids[0], txn.Txn.ID().String())

// Assert that the TxIDs field across both endpoint responses is the same
require.Equal(t, txngroupResponse["Txids"], groupDelta.Delta["Txids"])
}
88 changes: 88 additions & 0 deletions test/e2e-go/restAPI/restClient_test.go
Expand Up @@ -1568,6 +1568,94 @@ end:
assertBoxCount(numberOfBoxesRemaining)
}

func TestSimulateTxnTracerDevMode(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()

a := require.New(fixtures.SynchronizedTest(t))
var localFixture fixtures.RestClientFixture
localFixture.Setup(t, filepath.Join("nettemplates", "DevModeTxnTracerNetwork.json"))
defer localFixture.Shutdown()

testClient := localFixture.LibGoalClient

_, err := testClient.WaitForRound(1)
a.NoError(err)

wh, err := testClient.GetUnencryptedWalletHandle()
a.NoError(err)
addresses, err := testClient.ListAddresses(wh)
a.NoError(err)
senderBalance, senderAddress := getMaxBalAddr(t, testClient, addresses)
if senderAddress == "" {
t.Error("no addr with funds")
}
a.NoError(err)

toAddress := getDestAddr(t, testClient, nil, senderAddress, wh)
closeToAddress := getDestAddr(t, testClient, nil, senderAddress, wh)

// Ensure these accounts don't exist
receiverBalance, err := testClient.GetBalance(toAddress)
a.NoError(err)
a.Zero(receiverBalance)
closeToBalance, err := testClient.GetBalance(closeToAddress)
a.NoError(err)
a.Zero(closeToBalance)

txn, err := testClient.ConstructPayment(senderAddress, toAddress, 0, senderBalance/2, nil, closeToAddress, [32]byte{}, 0, 0)
a.NoError(err)
stxn, err := testClient.SignTransactionWithWallet(wh, nil, txn)
a.NoError(err)

currentRoundBeforeSimulate, err := testClient.CurrentRound()
a.NoError(err)

simulateRequest := v2.PreEncodedSimulateRequest{
TxnGroups: []v2.PreEncodedSimulateRequestTransactionGroup{
{
Txns: []transactions.SignedTxn{stxn},
},
},
}
result, err := testClient.SimulateTransactions(simulateRequest)
a.NoError(err)

currentAfterAfterSimulate, err := testClient.CurrentRound()
a.NoError(err)

// We can assert equality here since DevMode rounds are controlled by txn sends.
a.Equal(result.LastRound, currentRoundBeforeSimulate)
a.Equal(result.LastRound, currentAfterAfterSimulate)

closingAmount := senderBalance - txn.Fee.Raw - txn.Amount.Raw
expectedResult := v2.PreEncodedSimulateResponse{
Version: 2,
LastRound: result.LastRound, // checked above
TxnGroups: []v2.PreEncodedSimulateTxnGroupResult{
{
Txns: []v2.PreEncodedSimulateTxnResult{
{
Txn: v2.PreEncodedTxInfo{
Txn: stxn,
ClosingAmount: &closingAmount,
},
},
},
},
},
}
a.Equal(expectedResult, result)

// Ensure the transaction did not actually get applied to the ledger
receiverBalance, err = testClient.GetBalance(toAddress)
a.NoError(err)
a.Zero(receiverBalance)
closeToBalance, err = testClient.GetBalance(closeToAddress)
a.NoError(err)
a.Zero(closeToBalance)
}

func TestSimulateTransaction(t *testing.T) {
partitiontest.PartitionTest(t)
t.Parallel()
Expand Down

0 comments on commit 859238a

Please sign in to comment.