Skip to content

Commit

Permalink
Remove defaultAddress helper from platformvm service tests (ava-lab…
Browse files Browse the repository at this point in the history
  • Loading branch information
dhrubabasu authored Feb 23, 2024
1 parent 7c04667 commit 02d68b8
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions vms/platformvm/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,7 @@ var (

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

vm.ctx.Keystore = ks.NewBlockchainKeyStore(vm.ctx.ChainID)
return &Service{
vm: vm,
addrManager: avax.NewAddressManager(vm.ctx),
Expand All @@ -89,30 +84,30 @@ func defaultService(t *testing.T) (*Service, *mutableSharedMemory) {
}, mutableSharedMemory
}

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

service, _ := defaultService(t)
service.vm.ctx.Lock.Lock()
defer service.vm.ctx.Lock.Unlock()

ks := keystore.New(logging.NoLog{}, memdb.New())
require.NoError(ks.CreateUser(testUsername, testPassword))
service.vm.ctx.Keystore = ks.NewBlockchainKeyStore(service.vm.ctx.ChainID)

user, err := vmkeystore.NewUserFromKeystore(service.vm.ctx.Keystore, testUsername, testPassword)
require.NoError(err)

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

require.NoError(user.PutKeys(pk, keys[0]))
}

func TestExportKey(t *testing.T) {
require := require.New(t)
jsonString := `{"username":"ScoobyUser","password":"ShaggyPassword1Zoinks!","address":"` + testAddress + `"}`
service.vm.ctx.Lock.Unlock()

jsonString := `{"username":"` + testUsername + `","password":"` + testPassword + `","address":"` + testAddress + `"}`
args := ExportKeyArgs{}
require.NoError(json.Unmarshal([]byte(jsonString), &args))

service, _ := defaultService(t)
defaultAddress(t, service)

reply := ExportKeyReply{}
require.NoError(service.ExportKey(nil, &args, &reply))

Expand All @@ -123,7 +118,6 @@ func TestExportKey(t *testing.T) {
func TestGetTxStatus(t *testing.T) {
require := require.New(t)
service, mutableSharedMemory := defaultService(t)
defaultAddress(t, service)
service.vm.ctx.Lock.Lock()

recipientKey, err := secp256k1.NewPrivateKey()
Expand Down Expand Up @@ -276,7 +270,6 @@ func TestGetTx(t *testing.T) {
t.Run(testName, func(t *testing.T) {
require := require.New(t)
service, _ := defaultService(t)
defaultAddress(t, service)
service.vm.ctx.Lock.Lock()

tx, err := test.createTx(service)
Expand Down Expand Up @@ -341,7 +334,6 @@ func TestGetTx(t *testing.T) {
func TestGetBalance(t *testing.T) {
require := require.New(t)
service, _ := defaultService(t)
defaultAddress(t, service)

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

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

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

Expand Down

0 comments on commit 02d68b8

Please sign in to comment.