Skip to content

Commit 02d68b8

Browse files
authored
Remove defaultAddress helper from platformvm service tests (#2767)
1 parent 7c04667 commit 02d68b8

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

vms/platformvm/service_test.go

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,7 @@ var (
7474

7575
func defaultService(t *testing.T) (*Service, *mutableSharedMemory) {
7676
vm, _, mutableSharedMemory := defaultVM(t, latestFork)
77-
vm.ctx.Lock.Lock()
78-
defer vm.ctx.Lock.Unlock()
79-
ks := keystore.New(logging.NoLog{}, memdb.New())
80-
require.NoError(t, ks.CreateUser(testUsername, testPassword))
8177

82-
vm.ctx.Keystore = ks.NewBlockchainKeyStore(vm.ctx.ChainID)
8378
return &Service{
8479
vm: vm,
8580
addrManager: avax.NewAddressManager(vm.ctx),
@@ -89,30 +84,30 @@ func defaultService(t *testing.T) (*Service, *mutableSharedMemory) {
8984
}, mutableSharedMemory
9085
}
9186

92-
// Give user [testUsername] control of [testPrivateKey] and keys[0] (which is funded)
93-
func defaultAddress(t *testing.T, service *Service) {
87+
func TestExportKey(t *testing.T) {
9488
require := require.New(t)
9589

90+
service, _ := defaultService(t)
9691
service.vm.ctx.Lock.Lock()
97-
defer service.vm.ctx.Lock.Unlock()
92+
93+
ks := keystore.New(logging.NoLog{}, memdb.New())
94+
require.NoError(ks.CreateUser(testUsername, testPassword))
95+
service.vm.ctx.Keystore = ks.NewBlockchainKeyStore(service.vm.ctx.ChainID)
96+
9897
user, err := vmkeystore.NewUserFromKeystore(service.vm.ctx.Keystore, testUsername, testPassword)
9998
require.NoError(err)
10099

101100
pk, err := secp256k1.ToPrivateKey(testPrivateKey)
102101
require.NoError(err)
103102

104103
require.NoError(user.PutKeys(pk, keys[0]))
105-
}
106104

107-
func TestExportKey(t *testing.T) {
108-
require := require.New(t)
109-
jsonString := `{"username":"ScoobyUser","password":"ShaggyPassword1Zoinks!","address":"` + testAddress + `"}`
105+
service.vm.ctx.Lock.Unlock()
106+
107+
jsonString := `{"username":"` + testUsername + `","password":"` + testPassword + `","address":"` + testAddress + `"}`
110108
args := ExportKeyArgs{}
111109
require.NoError(json.Unmarshal([]byte(jsonString), &args))
112110

113-
service, _ := defaultService(t)
114-
defaultAddress(t, service)
115-
116111
reply := ExportKeyReply{}
117112
require.NoError(service.ExportKey(nil, &args, &reply))
118113

@@ -123,7 +118,6 @@ func TestExportKey(t *testing.T) {
123118
func TestGetTxStatus(t *testing.T) {
124119
require := require.New(t)
125120
service, mutableSharedMemory := defaultService(t)
126-
defaultAddress(t, service)
127121
service.vm.ctx.Lock.Lock()
128122

129123
recipientKey, err := secp256k1.NewPrivateKey()
@@ -276,7 +270,6 @@ func TestGetTx(t *testing.T) {
276270
t.Run(testName, func(t *testing.T) {
277271
require := require.New(t)
278272
service, _ := defaultService(t)
279-
defaultAddress(t, service)
280273
service.vm.ctx.Lock.Lock()
281274

282275
tx, err := test.createTx(service)
@@ -341,7 +334,6 @@ func TestGetTx(t *testing.T) {
341334
func TestGetBalance(t *testing.T) {
342335
require := require.New(t)
343336
service, _ := defaultService(t)
344-
defaultAddress(t, service)
345337

346338
// Ensure GetStake is correct for each of the genesis validators
347339
genesis, _ := defaultGenesis(t, service.vm.ctx.AVAXAssetID)
@@ -370,7 +362,6 @@ func TestGetBalance(t *testing.T) {
370362
func TestGetStake(t *testing.T) {
371363
require := require.New(t)
372364
service, _ := defaultService(t)
373-
defaultAddress(t, service)
374365

375366
// Ensure GetStake is correct for each of the genesis validators
376367
genesis, _ := defaultGenesis(t, service.vm.ctx.AVAXAssetID)
@@ -543,7 +534,6 @@ func TestGetStake(t *testing.T) {
543534
func TestGetCurrentValidators(t *testing.T) {
544535
require := require.New(t)
545536
service, _ := defaultService(t)
546-
defaultAddress(t, service)
547537

548538
genesis, _ := defaultGenesis(t, service.vm.ctx.AVAXAssetID)
549539

0 commit comments

Comments
 (0)