Skip to content

Commit

Permalink
Add comment for alias-base type compat test
Browse files Browse the repository at this point in the history
  • Loading branch information
iansuvak committed Jun 21, 2023
1 parent 4bd07f5 commit e52b870
Showing 1 changed file with 55 additions and 1 deletion.
56 changes: 55 additions & 1 deletion agreement/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,61 @@ import (
"github.com/algorand/go-algorand/data/basics"
)

// These types are defined to satisfy SortInterface used by
////////////////////////////////////////////////////////////////////////////////////////////
// These types are defined to satisfy SortInterface used by msgp to consistently sort maps with this type as key.
//
// We use base types as sort keys instead of the aliased types, i.e. basics.Round instead of the agreement local alias round.
// This is safe as demonstrated by the test below included as a comment.
// The test itself is not committed as it would require us to commit an unused test struct to non _test files
// in order to generate msgp Marshal/Unmarshall methods for it
//
// With rootRouteBasic defined as:
//
// type rootRouterBasic struct {
// _struct struct{} `codec:","`
//
// root actor // playerMachine (not restored: explicitly set on construction)
// proposalRoot listener // proposalMachine
// voteRoot listener // voteMachine
//
// ProposalManager proposalManager
// VoteAggregator voteAggregator
//
// Children map[basics.Round]*roundRouter `codec:"Children,allocbound=-"`
// }
// i.e. exactly the same but using basics.Round as the key instead of the alias the following test passes.
//
// func TestMsgpTypeAliasCompat(t *testing.T) {
// partitiontest.PartitionTest(t)
//
// randomRound := rand.Uint64()
// a := rootRouter{Children: map[round]*roundRouter{round(randomRound): {}}}
//
// b := rootRouterBasic{Children: map[basics.Round]*roundRouter{basics.Round(randomRound): {}}}
//
// require.NotEqual(t, a, b)
//
// aEnc := protocol.Encode(&a)
// bEnc := protocol.Encode(&b)
//
// require.Equal(t, aEnc, bEnc)
//
// var aDecA, bDecA rootRouter
// var aDecB, bDecB rootRouterBasic
//
// err := protocol.Decode(aEnc, &aDecA)
// require.NoError(t, err)
// err = protocol.Decode(bEnc, &bDecA)
// require.NoError(t, err)
// require.Equal(t, aDecA, bDecA)
//
// err = protocol.Decode(aEnc, &aDecB)
// require.NoError(t, err)
// err = protocol.Decode(bEnc, &bDecB)
// require.NoError(t, err)
// require.Equal(t, aDecB, bDecB)
// }
////////////////////////////////////////////////////////////////////////////////////////////

// SortAddress is re-exported from basics.Address since the interface is already defined there
//
Expand Down

0 comments on commit e52b870

Please sign in to comment.