From cc0a6a39e3bf9250e6269d72da7cfe592afa76c3 Mon Sep 17 00:00:00 2001 From: Oren Date: Sun, 15 Dec 2024 16:03:02 +0200 Subject: [PATCH] freeze after stake unit test --- x/pairing/keeper/helpers_test.go | 16 ++++++++++++ x/pairing/keeper/pairing_test.go | 44 ++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/x/pairing/keeper/helpers_test.go b/x/pairing/keeper/helpers_test.go index eea0eb175b..fef021192d 100644 --- a/x/pairing/keeper/helpers_test.go +++ b/x/pairing/keeper/helpers_test.go @@ -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 +} diff --git a/x/pairing/keeper/pairing_test.go b/x/pairing/keeper/pairing_test.go index c312411f1e..2972491723 100644 --- a/x/pairing/keeper/pairing_test.go +++ b/x/pairing/keeper/pairing_test.go @@ -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) +}