Skip to content

Commit

Permalink
chore: finish go1.20 bump (#1058)
Browse files Browse the repository at this point in the history
* more

* fix rands
  • Loading branch information
shaspitz authored Jun 22, 2023
1 parent 44ec75f commit ed04399
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/automated-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: "1.19" # The Go version to download (if necessary) and use.
go-version: "1.20" # The Go version to download (if necessary) and use.
# - name: Proto Check
# run: make proto-check
- name: Unit, integration and difference tests
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: "1.19" # The Go version to download (if necessary) and use.
go-version: "1.20" # The Go version to download (if necessary) and use.
- name: Test with coverage
run: go test -coverpkg=./x/... -coverprofile=coverage.out ./...
- name: SonarCloud Scan
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
steps:
- uses: actions/setup-go@v4
with:
go-version: "1.19"
go-version: "1.20"
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/manual-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
steps:
- uses: actions/setup-go@v4
with:
go-version: "1.19"
go-version: "1.20"
- uses: actions/checkout@v3

- name: Checkout LFS objects
Expand All @@ -20,7 +20,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v4
with:
go-version: "1.19" # The Go version to download (if necessary) and use.
go-version: "1.20" # The Go version to download (if necessary) and use.

- name: E2E tests
run: make test-e2e
2 changes: 1 addition & 1 deletion .github/workflows/nightly-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
steps:
- uses: actions/setup-go@v4
with:
go-version: "1.19"
go-version: "1.20"

- uses: actions/checkout@v3

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ For more details on the Replicated Security protocol, take a look at the [docs](
```bash
## For OSX or Linux

# go 1.18 (https://formulae.brew.sh/formula/go)
brew install go@1.19
# go 1.20 (https://formulae.brew.sh/formula/go)
brew install go@1.20
# jq (optional, for testnet) (https://formulae.brew.sh/formula/jq)
brew install jq
# docker (optional, for integration tests, testnet) (https://docs.docker.com/get-docker/)
Expand Down
41 changes: 26 additions & 15 deletions x/ccv/provider/keeper/key_assignment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ func TestGetAllValidatorConsumerPubKey(t *testing.T) {
pk, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t))
defer ctrl.Finish()

rand.Seed(time.Now().Unix())
seed := time.Now().UnixNano()
rng := rand.New(rand.NewSource(seed))

chainIDs := []string{"consumer-1", "consumer-2", "consumer-3"}
numAssignments := 10
testAssignments := []types.ValidatorConsumerPubKey{}
Expand All @@ -56,7 +58,7 @@ func TestGetAllValidatorConsumerPubKey(t *testing.T) {
providerAddr := cryptotestutil.NewCryptoIdentityFromIntSeed(numAssignments + i).ProviderConsAddress()
testAssignments = append(testAssignments,
types.ValidatorConsumerPubKey{
ChainId: chainIDs[rand.Intn(len(chainIDs))],
ChainId: chainIDs[rng.Intn(len(chainIDs))],
ProviderAddr: providerAddr.ToSdkConsAddr(),
ConsumerKey: &consumerKey,
},
Expand Down Expand Up @@ -125,7 +127,9 @@ func TestGetAllValidatorsByConsumerAddr(t *testing.T) {
pk, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t))
defer ctrl.Finish()

rand.Seed(time.Now().Unix())
seed := time.Now().UnixNano()
rng := rand.New(rand.NewSource(seed))

chainIDs := []string{"consumer-1", "consumer-2", "consumer-3"}
numAssignments := 10
testAssignments := []types.ValidatorByConsumerAddr{}
Expand All @@ -134,7 +138,7 @@ func TestGetAllValidatorsByConsumerAddr(t *testing.T) {
providerAddr := cryptotestutil.NewCryptoIdentityFromIntSeed(numAssignments + i).ProviderConsAddress()
testAssignments = append(testAssignments,
types.ValidatorByConsumerAddr{
ChainId: chainIDs[rand.Intn(len(chainIDs))],
ChainId: chainIDs[rng.Intn(len(chainIDs))],
ConsumerAddr: consumerAddr.ToSdkConsAddr(),
ProviderAddr: providerAddr.ToSdkConsAddr(),
},
Expand Down Expand Up @@ -205,7 +209,9 @@ func TestGetAllKeyAssignmentReplacements(t *testing.T) {

chainID := "consumer-1"

rand.Seed(time.Now().Unix())
seed := time.Now().UnixNano()
rng := rand.New(rand.NewSource(seed))

numAssignments := 10
testAssignments := []types.KeyAssignmentReplacement{}
for i := 0; i < numAssignments; i++ {
Expand All @@ -215,7 +221,7 @@ func TestGetAllKeyAssignmentReplacements(t *testing.T) {
types.KeyAssignmentReplacement{
ProviderAddr: providerAddr.ToSdkConsAddr(),
PrevCKey: &consumerKey,
Power: rand.Int63(),
Power: rng.Int63(),
},
)
}
Expand Down Expand Up @@ -264,7 +270,9 @@ func TestGetAllConsumerAddrsToPrune(t *testing.T) {
pk, ctx, ctrl, _ := testkeeper.GetProviderKeeperAndCtx(t, testkeeper.NewInMemKeeperParams(t))
defer ctrl.Finish()

rand.Seed(time.Now().Unix())
seed := time.Now().UnixNano()
rng := rand.New(rand.NewSource(seed))

chainIDs := []string{"consumer-1", "consumer-2", "consumer-3"}
numAssignments := 10
testAssignments := []types.ConsumerAddrsToPrune{}
Expand All @@ -276,8 +284,8 @@ func TestGetAllConsumerAddrsToPrune(t *testing.T) {
}
testAssignments = append(testAssignments,
types.ConsumerAddrsToPrune{
ChainId: chainIDs[rand.Intn(len(chainIDs))],
VscId: rand.Uint64(),
ChainId: chainIDs[rng.Intn(len(chainIDs))],
VscId: rng.Uint64(),
ConsumerAddrs: &consumerAddresses,
},
)
Expand Down Expand Up @@ -705,14 +713,17 @@ func TestSimulatedAssignmentsAndUpdateApplication(t *testing.T) {
assignableIDS = append(assignableIDS, cryptotestutil.NewCryptoIdentityFromIntSeed(i))
}

seed := time.Now().UnixNano()
rng := rand.New(rand.NewSource(seed))

// Helper: simulates creation of staking module EndBlock updates.
getStakingUpdates := func() (ret []abci.ValidatorUpdate) {
// Get a random set of validators to update. It is important to test subsets of all validators.
validators := rand.Perm(len(providerIDS))[0:rand.Intn(len(providerIDS)+1)]
validators := rng.Perm(len(providerIDS))[0:rng.Intn(len(providerIDS)+1)]
for _, i := range validators {
// Power 0, 1, or 2 represents
// deletion, update (from 0 or 2), update (from 0 or 1)
power := rand.Intn(3)
power := rng.Intn(3)
ret = append(ret, abci.ValidatorUpdate{
PubKey: providerIDS[i].TMProtoCryptoPublicKey(),
Power: int64(power),
Expand All @@ -723,9 +734,9 @@ func TestSimulatedAssignmentsAndUpdateApplication(t *testing.T) {

// Helper: simulates creation of assignment tx's to be done.
getAssignments := func() (ret []Assignment) {
for i, numAssignments := 0, rand.Intn(NUM_ASSIGNMENTS_PER_BLOCK_MAX); i < numAssignments; i++ {
randomIxP := rand.Intn(len(providerIDS))
randomIxC := rand.Intn(len(assignableIDS))
for i, numAssignments := 0, rng.Intn(NUM_ASSIGNMENTS_PER_BLOCK_MAX); i < numAssignments; i++ {
randomIxP := rng.Intn(len(providerIDS))
randomIxC := rng.Intn(len(assignableIDS))
ret = append(ret, Assignment{
val: providerIDS[randomIxP].SDKStakingValidator(),
ck: assignableIDS[randomIxC].TMProtoCryptoPublicKey(),
Expand Down Expand Up @@ -832,7 +843,7 @@ func TestSimulatedAssignmentsAndUpdateApplication(t *testing.T) {
// delivery of maturity packets from the consumer chain.
prunedVscid := greatestPrunedVSCID +
// +1 and -1 because id was incremented (-1), (+1) to make upper bound inclusive
rand.Intn(int(k.GetValidatorSetUpdateId(ctx))+1-1-greatestPrunedVSCID)
rng.Intn(int(k.GetValidatorSetUpdateId(ctx))+1-1-greatestPrunedVSCID)
k.PruneKeyAssignments(ctx, CHAINID, uint64(prunedVscid))
greatestPrunedVSCID = prunedVscid

Expand Down
10 changes: 6 additions & 4 deletions x/ccv/provider/keeper/throttle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -784,8 +784,9 @@ func TestGlobalSlashEntryDeletion(t *testing.T) {

// Instantiate shuffled copy of above slice
shuffledEntries := append([]providertypes.GlobalSlashEntry{}, entries...)
rand.Seed(now.UnixNano())
rand.Shuffle(len(shuffledEntries), func(i, j int) {
seed := time.Now().UnixNano()
rng := rand.New(rand.NewSource(seed))
rng.Shuffle(len(shuffledEntries), func(i, j int) {
shuffledEntries[i], shuffledEntries[j] = shuffledEntries[j], shuffledEntries[i]
})

Expand Down Expand Up @@ -1192,7 +1193,8 @@ func TestPanicIfTooMuchThrottledPacketData(t *testing.T) {
defaultParams.MaxThrottledPackets = tc.max
providerKeeper.SetParams(ctx, defaultParams)

rand.Seed(time.Now().UnixNano())
seed := time.Now().UnixNano()
rng := rand.New(rand.NewSource(seed))

// Queuing up a couple data instances for another chain shouldn't matter
err := providerKeeper.QueueThrottledPacketData(ctx, "chain-17", 0, testkeeper.GetNewSlashPacketData())
Expand All @@ -1203,7 +1205,7 @@ func TestPanicIfTooMuchThrottledPacketData(t *testing.T) {
// Queue packet data instances until we reach the max (some slash packets, some VSC matured packets)
reachedMax := false
for i := 0; i < int(tc.max); i++ {
randBool := rand.Intn(2) == 0
randBool := rng.Intn(2) == 0
var data interface{}
if randBool {
data = testkeeper.GetNewSlashPacketData()
Expand Down

0 comments on commit ed04399

Please sign in to comment.