Skip to content

Commit

Permalink
freeze after stake unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
oren-lava committed Dec 15, 2024
1 parent c07dbc6 commit cc0a6a3
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
16 changes: 16 additions & 0 deletions x/pairing/keeper/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,19 @@ func (ts *tester) newRelaySession(
}
return relaySession
}

func (ts *tester) isProviderFrozen(provider string, chain string) bool {
res, err := ts.QueryPairingProvider(provider, chain)
require.NoError(ts.T, err)
foundChain := false
for _, stakeEntry := range res.StakeEntries {
if stakeEntry.Address == provider && stakeEntry.Chain == chain {
foundChain = true
return stakeEntry.IsFrozen()
}
}
if !foundChain {
require.Fail(ts.T, "provider not staked in chain", "provider: %s, chain: %s", provider, chain)
}
return false
}
44 changes: 44 additions & 0 deletions x/pairing/keeper/pairing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2509,3 +2509,47 @@ func TestMaxEndpointPerGeolocationLimit(t *testing.T) {
)
require.Error(t, err)
}

// TestStakeNotAffectingFreeze checks the following scenario:
// 1. a provider is staked and frozen
// 2. the provider stakes to a new chain
// 3. the provider's freeze status in the original chain is not affected
func TestStakeNotAffectingFreeze(t *testing.T) {
ts := newTester(t)
ts.SetupAccounts(0, 0, 1) // 0 sub, 0 adm, 1 dev

var balance int64 = 10000
stake := balance / 10

// Create provider account and stake them to first spec
acc, addr := ts.AddAccount(common.PROVIDER, 1, balance)
err := ts.StakeProvider(acc.GetVaultAddr(), addr, ts.spec, stake)
require.NoError(t, err)

ts.AdvanceEpoch()

// Freeze the provider
_, err = ts.TxPairingFreezeProvider(addr, ts.spec.Index)
require.NoError(t, err)

// Verify provider is frozen
frozen := ts.isProviderFrozen(addr, ts.spec.Index)
require.True(t, frozen)

// Create a second spec and stake provider to it
spec1 := ts.spec
spec1Name := "spec1"
spec1.Index, spec1.Name = spec1Name, spec1Name
ts.AddSpec(spec1Name, spec1)
err = ts.StakeProvider(acc.GetVaultAddr(), addr, spec1, stake)
require.NoError(t, err)
ts.AdvanceEpoch()

// Verify provider is still frozen in original spec
frozen = ts.isProviderFrozen(addr, ts.spec.Index)
require.True(t, frozen)

// Verify provider is not frozen in new spec
frozen = ts.isProviderFrozen(addr, spec1.Index)
require.False(t, frozen)
}

0 comments on commit cc0a6a3

Please sign in to comment.