Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PVM, DAC] Bugfixes, tests, early-exit by fail #284

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion vms/platformvm/camino_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func newCaminoGenesisWithUTXOs(caminoGenesisConfig api.Camino, genesisUTXOs []ap
Addresses: []string{addr},
},
Staked: []api.UTXO{{
Amount: json.Uint64(defaultWeight),
Amount: json.Uint64(defaultCaminoValidatorWeight),
Address: addr,
}},
}
Expand Down
27 changes: 20 additions & 7 deletions vms/platformvm/camino_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ import (
func TestGetCaminoBalance(t *testing.T) {
hrp := constants.NetworkIDToHRP[testNetworkID]

id := keys[0].PublicKey().Address()
id := caminoPreFundedKeys[0].PublicKey().Address()
addr, err := address.FormatBech32(hrp, id.Bytes())
require.NoError(t, err)

tests := map[string]struct {
camino api.Camino
genesisUTXOs []api.UTXO
genesisUTXOs []api.UTXO // unlocked utxos
address string
bonded uint64
deposited uint64
depositedBonded uint64
bonded uint64 // additional (to existing genesis validator bond) bonded utxos
deposited uint64 // additional deposited utxos
depositedBonded uint64 // additional depositedBonded utxos
expectedError error
}{
"Genesis Validator with added balance": {
Expand Down Expand Up @@ -135,6 +135,18 @@ func TestGetCaminoBalance(t *testing.T) {
require.NoError(t, err)
}

if tt.bonded != 0 {
outputOwners := secp256k1fx.OutputOwners{
Locktime: 0,
Threshold: 1,
Addrs: []ids.ShortID{keys[0].PublicKey().Address()},
}
utxo := generateTestUTXO(ids.GenerateTestID(), avaxAssetID, tt.bonded, outputOwners, ids.Empty, ids.GenerateTestID())
service.vm.state.AddUTXO(utxo)
err := service.vm.state.Commit()
require.NoError(t, err)
}

if tt.depositedBonded != 0 {
outputOwners := secp256k1fx.OutputOwners{
Locktime: 0,
Expand All @@ -153,7 +165,7 @@ func TestGetCaminoBalance(t *testing.T) {
return
}
require.NoError(t, err)
expectedBalance := json.Uint64(defaultBalance + tt.bonded + tt.deposited + tt.depositedBonded)
expectedBalance := json.Uint64(defaultCaminoValidatorWeight + defaultBalance + tt.bonded + tt.deposited + tt.depositedBonded)

if !tt.camino.LockModeBondDeposit {
response := responseWrapper.avax
Expand All @@ -163,8 +175,9 @@ func TestGetCaminoBalance(t *testing.T) {
require.Equal(t, json.Uint64(defaultBalance), response.Unlocked, "Wrong unlocked balance. Expected %d ; Returned %d", defaultBalance, response.Unlocked)
} else {
response := responseWrapper.camino
require.Equal(t, json.Uint64(defaultBalance+tt.bonded+tt.deposited+tt.depositedBonded), response.Balances[avaxAssetID], "Wrong balance. Expected %d ; Returned %d", expectedBalance, response.Balances[avaxAssetID])
require.Equal(t, json.Uint64(defaultCaminoValidatorWeight+defaultBalance+tt.bonded+tt.deposited+tt.depositedBonded), response.Balances[avaxAssetID], "Wrong balance. Expected %d ; Returned %d", expectedBalance, response.Balances[avaxAssetID])
require.Equal(t, json.Uint64(tt.deposited), response.DepositedOutputs[avaxAssetID], "Wrong deposited balance. Expected %d ; Returned %d", tt.deposited, response.DepositedOutputs[avaxAssetID])
require.Equal(t, json.Uint64(defaultCaminoValidatorWeight+tt.bonded), response.BondedOutputs[avaxAssetID], "Wrong bonded balance. Expected %d ; Returned %d", tt.bonded, response.BondedOutputs[avaxAssetID])
require.Equal(t, json.Uint64(tt.depositedBonded), response.DepositedBondedOutputs[avaxAssetID], "Wrong depositedBonded balance. Expected %d ; Returned %d", tt.depositedBonded, response.DepositedBondedOutputs[avaxAssetID])
require.Equal(t, json.Uint64(defaultBalance), response.UnlockedOutputs[avaxAssetID], "Wrong unlocked balance. Expected %d ; Returned %d", defaultBalance, response.UnlockedOutputs[avaxAssetID])
}
Expand Down
Loading
Loading