Skip to content

Commit a974e34

Browse files
authored
testing: update Test5MAssetsScenario e2e test (#3750)
## Summary This PR improves the test in the following ways: 1. The checkPoint method is no longer timer-based; instead, it's using the WaitForBlock which moves the blocking operation to the node. 2. The generated accounts secret keys are now deterministic. This would allows repeated runs to have the same set of keys. 3. More testing was added for return variables across the test. ## Test Plan This is a test.
1 parent b5c87fc commit a974e34

File tree

1 file changed

+24
-28
lines changed

1 file changed

+24
-28
lines changed

test/e2e-go/features/accountPerf/sixMillion_test.go

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ func getAccountInformation(
138138
func getAccountApplicationInformation(
139139
fixture *fixtures.RestClientFixture,
140140
address string,
141-
appID uint64,
142-
context string) (appInfo generated.AccountApplicationResponse, err error) {
141+
appID uint64) (appInfo generated.AccountApplicationResponse, err error) {
143142

144143
appInfo, err = fixture.AlgodClient.AccountApplicationInformation(address, appID)
145144
return
@@ -321,12 +320,14 @@ func test5MAssets(t *testing.T, scenario int) {
321320
}
322321
}
323322

324-
// generates numAccounts keys
323+
// generates numAccounts keys; we generate the same seeds here when generating the secret keys
324+
// so that this test would be reproducible.
325325
func generateKeys(numAccounts int) (keys []psKey) {
326326
keys = make([]psKey, 0, numAccounts)
327327
var seed crypto.Seed
328+
seed[len(seed)-1] = 1
328329
for a := 0; a < numAccounts; a++ {
329-
crypto.RandBytes(seed[:])
330+
seed[0], seed[1], seed[2], seed[3] = byte(a), byte(a>>8), byte(a>>16), byte(a>>24)
330331
privateKey := crypto.GenerateSignatureSecrets(seed)
331332
publicKey := basics.Address(privateKey.SignatureVerifier)
332333
keys = append(keys, psKey{pk: publicKey, sk: privateKey})
@@ -527,6 +528,7 @@ func scenarioA(
527528
printStdOut(acci, numberOfAccounts, "ScenarioA: Accepting assets from acct")
528529
info, err := getAccountInformation(fixture, 0, assetsPerAccount, nacc.pk.String(), "ScenarioA opt-in assets", log)
529530
require.NoError(t, err)
531+
require.Equal(t, int(assetsPerAccount), len(*info.Assets)) // test the asset holding.
530532
for _, asset := range *info.Assets {
531533
select {
532534
case <-stopChan:
@@ -565,6 +567,7 @@ func scenarioA(
565567

566568
info, err := getAccountInformation(fixture, 0, assetsPerAccount, nacc.pk.String(), "ScenarioA transfer assets", log)
567569
require.NoError(t, err)
570+
require.Equal(t, int(assetsPerAccount), len(*info.Assets)) // test the asset holding.
568571
for _, asset := range *info.Assets {
569572
select {
570573
case <-stopChan:
@@ -601,6 +604,7 @@ func scenarioA(
601604
printStdOut(nai, numberOfAccounts, "ScenarioA: Verifying assets from account")
602605
info, err := getAccountInformation(fixture, 0, assetsPerAccount, nacc.pk.String(), "ScenarioA verify assets", log)
603606
require.NoError(t, err)
607+
require.Equal(t, int(assetsPerAccount), len(*info.Assets)) // test the asset holding.
604608
for _, asset := range *info.Assets {
605609
select {
606610
case <-stopChan:
@@ -677,9 +681,9 @@ func scenarioB(
677681
log.Infof("Verifying assets...")
678682
// Verify the assets are transfered here
679683
tAssetAmt := uint64(0)
680-
info, err = fixture.AlgodClient.AccountInformationV2(baseAcct.pk.String(), false)
681-
require.NoError(t, err)
682684
counter = 0
685+
// this loop iterates over all the range of potentail assets, tries to confirm all of them.
686+
// many of these are expected to be non-existing.
683687
for aid := uint64(0); counter < numberOfAssets && aid < 2*numberOfAssets; aid++ {
684688
select {
685689
case <-stopChan:
@@ -694,6 +698,7 @@ func scenarioB(
694698
}
695699
counter++
696700
require.NoError(t, err)
701+
require.NotZero(t, assHold.AssetHolding.Amount)
697702
tAssetAmt += assHold.AssetHolding.Amount
698703
printStdOut(int(counter), numberOfAssets, "ScenarioB: Verifying assets")
699704
}
@@ -818,15 +823,16 @@ func scenarioC(
818823
printStdOut(nai, numberOfAccounts, "ScenarioC: Verifying apps opt-in from account")
819824
info, err := getAccountInformation(fixture, appsPerAccount, 0, nacc.pk.String(), "ScenarioC verify accounts", log)
820825
require.NoError(t, err)
821-
826+
require.Equal(t, appsPerAccount, info.TotalAppsOptedIn) // since we opted into the app
822827
for _, capp := range *info.CreatedApps {
823-
appInfo, err := getAccountApplicationInformation(fixture, ownAllAccount.pk.String(), capp.Id, "verifying after optin")
828+
appInfo, err := getAccountApplicationInformation(fixture, ownAllAccount.pk.String(), capp.Id) // "verifying after optin"
824829
if err != nil {
825830
log.Errorf("account: %s appid: %d error %s", ownAllAccount.pk, capp.Id, err)
826831
continue
827832
}
828833
require.Equal(t, uint64(1), (*appInfo.AppLocalState.KeyValue)[0].Value.Uint)
829834
require.Equal(t, uint64(2), (*capp.Params.GlobalState)[0].Value.Uint)
835+
require.Nil(t, appInfo.CreatedApp)
830836
}
831837
}
832838

@@ -866,15 +872,16 @@ func scenarioC(
866872
printStdOut(nai, numberOfAccounts, "ScenarioC: Verifying app calls from account")
867873
info, err := getAccountInformation(fixture, appsPerAccount, 0, nacc.pk.String(), "ScenarioC verify accounts", log)
868874
require.NoError(t, err)
869-
875+
require.Equal(t, appsPerAccount, info.TotalAppsOptedIn) // since we opted into the app
870876
for _, capp := range *info.CreatedApps {
871-
appInfo, err := getAccountApplicationInformation(fixture, ownAllAccount.pk.String(), capp.Id, "after call")
877+
appInfo, err := getAccountApplicationInformation(fixture, ownAllAccount.pk.String(), capp.Id) // "after call"
872878
if err != nil {
873879
log.Errorf("account: %s appid: %d error %s", ownAllAccount.pk, capp.Id, err)
874880
continue
875881
}
876882
require.Equal(t, uint64(2), (*appInfo.AppLocalState.KeyValue)[0].Value.Uint)
877883
require.Equal(t, uint64(3), (*capp.Params.GlobalState)[0].Value.Uint)
884+
require.Nil(t, appInfo.CreatedApp)
878885
}
879886
}
880887
}
@@ -1010,30 +1017,19 @@ func handleError(err error, message string, errChan chan<- error) {
10101017

10111018
// handle the counters to prepare and send transactions in batches of MaxTxnLife transactions
10121019
func checkPoint(counter, firstValid, tLife uint64, force bool, fixture *fixtures.RestClientFixture, log logging.Logger) (newCounter, nextFirstValid uint64, err error) {
1013-
waitBlock := 5
10141020
lastRound := firstValid + counter - 1
10151021
if force || counter == tLife {
10161022
if verbose {
10171023
fmt.Printf("Waiting for round %d...", int(lastRound))
10181024
}
1019-
for x := 0; x < 1000; x++ {
1020-
err := fixture.WaitForRound(lastRound, time.Duration(waitBlock)*time.Second)
1021-
if err == nil {
1022-
if verbose {
1023-
fmt.Printf(" waited less than %d sec, done.\n", (x+1)*waitBlock)
1024-
}
1025-
status, err := fixture.AlgodClient.Status()
1026-
if err != nil {
1027-
return 0, lastRound + 1, nil
1028-
}
1029-
return 0, status.LastRound + 1, nil
1030-
}
1031-
if verbose {
1032-
fmt.Printf(" waited %d sec, continue waiting...", (x+1)*waitBlock)
1033-
}
1025+
nodeStat, err := fixture.AlgodClient.WaitForBlock(basics.Round(lastRound - 1))
1026+
if err != nil {
1027+
return 0, 0, fmt.Errorf("failed to wait for block %d : %w", lastRound, err)
1028+
}
1029+
if nodeStat.LastRound < lastRound {
1030+
return 0, 0, fmt.Errorf("failed to wait for block %d : node is at round %d", lastRound, nodeStat.LastRound)
10341031
}
1035-
log.Debugf("Giving up!")
1036-
return 0, 0, fmt.Errorf("waited for round %d for %d seconds. Giving up", firstValid+counter, 1000*waitBlock)
1032+
return 0, nodeStat.LastRound + 1, nil
10371033
}
10381034
return counter, firstValid, nil
10391035
}

0 commit comments

Comments
 (0)