Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 7a0dfda
Author: Joshua Kim <[email protected]>
Date:   Tue Dec 12 03:29:47 2023 -0500

    testing structs

    Signed-off-by: Joshua Kim <[email protected]>

commit 58d2779
Author: Dhruba Basu <[email protected]>
Date:   Tue Dec 19 14:01:16 2023 -0500

    Dedupe secp256k1 key usage in tests (#2511)

commit 6c64372
Author: Dhruba Basu <[email protected]>
Date:   Tue Dec 19 11:45:58 2023 -0500

    Remove unused `AcceptorTracker` struct (#2508)

commit 7a9bdad
Author: Dhruba Basu <[email protected]>
Date:   Tue Dec 19 10:44:20 2023 -0500

    Remove unused `BuildGenesisTest` function (#2503)

commit 44d71db
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Mon Dec 18 19:05:26 2023 -0500

    Bump golang.org/x/crypto from 0.14.0 to 0.17.0 (#2502)

    Signed-off-by: dependabot[bot] <[email protected]>
    Signed-off-by: Stephen Buttolph <[email protected]>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
    Co-authored-by: Stephen Buttolph <[email protected]>

commit aa764bb
Author: Alberto Benegiamo <[email protected]>
Date:   Mon Dec 18 16:00:17 2023 -0700

    Drop Pending Stakers 5 - validated PostDurango StakerTxs (#2314)

    Co-authored-by: Stephen Buttolph <[email protected]>
    Co-authored-by: dhrubabasu <[email protected]>

Signed-off-by: Joshua Kim <[email protected]>
  • Loading branch information
joshua-kim committed Dec 19, 2023
1 parent 7172d4f commit 23f7cdd
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 127 deletions.
28 changes: 0 additions & 28 deletions snow/acceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

var (
_ Acceptor = noOpAcceptor{}
_ Acceptor = (*AcceptorTracker)(nil)
_ Acceptor = acceptorWrapper{}

_ AcceptorGroup = (*acceptorGroup)(nil)
Expand All @@ -38,33 +37,6 @@ func (noOpAcceptor) Accept(*ConsensusContext, ids.ID, []byte) error {
return nil
}

// AcceptorTracker tracks the dispatched accept events by its ID and counts.
// Useful for testing.
type AcceptorTracker struct {
lock sync.RWMutex
accepted map[ids.ID]int
}

func NewAcceptorTracker() *AcceptorTracker {
return &AcceptorTracker{
accepted: make(map[ids.ID]int),
}
}

func (a *AcceptorTracker) Accept(_ *ConsensusContext, containerID ids.ID, _ []byte) error {
a.lock.Lock()
a.accepted[containerID]++
a.lock.Unlock()
return nil
}

func (a *AcceptorTracker) IsAccepted(containerID ids.ID) (int, bool) {
a.lock.RLock()
count, ok := a.accepted[containerID]
a.lock.RUnlock()
return count, ok
}

type acceptorWrapper struct {
Acceptor

Expand Down
16 changes: 1 addition & 15 deletions tests/e2e/static-handlers/suites.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/tests/fixture/e2e"
"github.com/ava-labs/avalanchego/utils/cb58"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"
"github.com/ava-labs/avalanchego/utils/formatting"
Expand Down Expand Up @@ -114,20 +113,7 @@ var _ = ginkgo.Describe("[StaticHandlers]", func() {
})

ginkgo.It("can make calls to platformvm static api", func() {
keys := []*secp256k1.PrivateKey{}
for _, key := range []string{
"24jUJ9vZexUM6expyMcT48LBx27k1m7xpraoV62oSQAHdziao5",
"2MMvUMsxx6zsHSNXJdFD8yc5XkancvwyKPwpw4xUK3TCGDuNBY",
"cxb7KpGWhDMALTjNNSJ7UQkkomPesyWAPUaWRGdyeBNzR6f35",
"ewoqjP7PxY4yr3iLTpLisriqt94hdyDFNgchSxGGztUrTXtNN",
"2RWLv6YVEXDiWLpaCbXhhqxtLbnFaKQsWPSSMSPhpWo47uJAeV",
} {
privKeyBytes, err := cb58.Decode(key)
require.NoError(err)
pk, err := secp256k1.ToPrivateKey(privKeyBytes)
require.NoError(err)
keys = append(keys, pk)
}
keys := secp256k1.TestKeys()

genesisUTXOs := make([]api.UTXO, len(keys))
hrp := constants.NetworkIDToHRP[constants.UnitTestID]
Expand Down
17 changes: 5 additions & 12 deletions vms/avm/environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"github.com/ava-labs/avalanchego/snow"
"github.com/ava-labs/avalanchego/snow/engine/common"
"github.com/ava-labs/avalanchego/snow/validators"
"github.com/ava-labs/avalanchego/utils/cb58"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/crypto/secp256k1"
"github.com/ava-labs/avalanchego/utils/formatting"
Expand Down Expand Up @@ -70,22 +69,16 @@ var (
chainID = ids.ID{5, 4, 3, 2, 1}
assetID = ids.ID{1, 2, 3}

keys []*secp256k1.PrivateKey
addrs []ids.ShortID // addrs[i] corresponds to keys[i]
keys = secp256k1.TestKeys()[:3] // TODO: Remove [:3]
addrs []ids.ShortID // addrs[i] corresponds to keys[i]

errMissing = errors.New("missing")
)

func init() {
for _, key := range []string{
"24jUJ9vZexUM6expyMcT48LBx27k1m7xpraoV62oSQAHdziao5",
"2MMvUMsxx6zsHSNXJdFD8yc5XkancvwyKPwpw4xUK3TCGDuNBY",
"cxb7KpGWhDMALTjNNSJ7UQkkomPesyWAPUaWRGdyeBNzR6f35",
} {
keyBytes, _ := cb58.Decode(key)
pk, _ := secp256k1.ToPrivateKey(keyBytes)
keys = append(keys, pk)
addrs = append(addrs, pk.PublicKey().Address())
addrs = make([]ids.ShortID, len(keys))
for i, key := range keys {
addrs[i] = key.Address()
}
}

Expand Down
72 changes: 0 additions & 72 deletions vms/platformvm/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,78 +243,6 @@ func defaultGenesis(t *testing.T) (*api.BuildGenesisArgs, []byte) {
return &buildGenesisArgs, genesisBytes
}

// Returns:
// 1) The genesis state
// 2) The byte representation of the default genesis for tests
func BuildGenesisTest(t *testing.T) (*api.BuildGenesisArgs, []byte) {
return BuildGenesisTestWithArgs(t, nil)
}

// Returns:
// 1) The genesis state
// 2) The byte representation of the default genesis for tests
func BuildGenesisTestWithArgs(t *testing.T, args *api.BuildGenesisArgs) (*api.BuildGenesisArgs, []byte) {
require := require.New(t)
genesisUTXOs := make([]api.UTXO, len(keys))
for i, key := range keys {
id := key.PublicKey().Address()
addr, err := address.FormatBech32(constants.UnitTestHRP, id.Bytes())
require.NoError(err)

genesisUTXOs[i] = api.UTXO{
Amount: json.Uint64(defaultBalance),
Address: addr,
}
}

genesisValidators := make([]api.GenesisPermissionlessValidator, len(genesisNodeIDs))
for i, nodeID := range genesisNodeIDs {
addr, err := address.FormatBech32(constants.UnitTestHRP, nodeID.Bytes())
require.NoError(err)

genesisValidators[i] = api.GenesisPermissionlessValidator{
GenesisValidator: api.GenesisValidator{
StartTime: json.Uint64(defaultValidateStartTime.Unix()),
EndTime: json.Uint64(defaultValidateEndTime.Unix()),
NodeID: nodeID,
},
RewardOwner: &api.Owner{
Threshold: 1,
Addresses: []string{addr},
},
Staked: []api.UTXO{{
Amount: json.Uint64(defaultWeight),
Address: addr,
}},
DelegationFee: reward.PercentDenominator,
}
}

buildGenesisArgs := api.BuildGenesisArgs{
NetworkID: json.Uint32(constants.UnitTestID),
AvaxAssetID: avaxAssetID,
UTXOs: genesisUTXOs,
Validators: genesisValidators,
Chains: nil,
Time: json.Uint64(defaultGenesisTime.Unix()),
InitialSupply: json.Uint64(360 * units.MegaAvax),
Encoding: formatting.Hex,
}

if args != nil {
buildGenesisArgs = *args
}

buildGenesisResponse := api.BuildGenesisReply{}
platformvmSS := api.StaticService{}
require.NoError(platformvmSS.BuildGenesis(nil, &buildGenesisArgs, &buildGenesisResponse))

genesisBytes, err := formatting.Decode(buildGenesisResponse.Encoding, buildGenesisResponse.Bytes)
require.NoError(err)

return &buildGenesisArgs, genesisBytes
}

func defaultVM(t *testing.T, fork activeFork) (*VM, database.Database, *mutableSharedMemory) {
require := require.New(t)
var (
Expand Down

0 comments on commit 23f7cdd

Please sign in to comment.