github.com/MetalBlockchain/metalgo@v1.11.9/vms/platformvm/txs/priorities_test.go (about)

     1  // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package txs
     5  
     6  import (
     7  	"fmt"
     8  	"testing"
     9  
    10  	"github.com/stretchr/testify/require"
    11  )
    12  
    13  func TestPriorityIsCurrent(t *testing.T) {
    14  	tests := []struct {
    15  		priority Priority
    16  		expected bool
    17  	}{
    18  		{
    19  			priority: PrimaryNetworkDelegatorApricotPendingPriority,
    20  			expected: false,
    21  		},
    22  		{
    23  			priority: PrimaryNetworkValidatorPendingPriority,
    24  			expected: false,
    25  		},
    26  		{
    27  			priority: PrimaryNetworkDelegatorBanffPendingPriority,
    28  			expected: false,
    29  		},
    30  		{
    31  			priority: SubnetPermissionlessValidatorPendingPriority,
    32  			expected: false,
    33  		},
    34  		{
    35  			priority: SubnetPermissionlessDelegatorPendingPriority,
    36  			expected: false,
    37  		},
    38  		{
    39  			priority: SubnetPermissionedValidatorPendingPriority,
    40  			expected: false,
    41  		},
    42  		{
    43  			priority: SubnetPermissionedValidatorCurrentPriority,
    44  			expected: true,
    45  		},
    46  		{
    47  			priority: SubnetPermissionlessDelegatorCurrentPriority,
    48  			expected: true,
    49  		},
    50  		{
    51  			priority: SubnetPermissionlessValidatorCurrentPriority,
    52  			expected: true,
    53  		},
    54  		{
    55  			priority: PrimaryNetworkDelegatorCurrentPriority,
    56  			expected: true,
    57  		},
    58  		{
    59  			priority: PrimaryNetworkValidatorCurrentPriority,
    60  			expected: true,
    61  		},
    62  	}
    63  	for _, test := range tests {
    64  		t.Run(fmt.Sprintf("%d", test.priority), func(t *testing.T) {
    65  			require.Equal(t, test.expected, test.priority.IsCurrent())
    66  		})
    67  	}
    68  }
    69  
    70  func TestPriorityIsPending(t *testing.T) {
    71  	tests := []struct {
    72  		priority Priority
    73  		expected bool
    74  	}{
    75  		{
    76  			priority: PrimaryNetworkDelegatorApricotPendingPriority,
    77  			expected: true,
    78  		},
    79  		{
    80  			priority: PrimaryNetworkValidatorPendingPriority,
    81  			expected: true,
    82  		},
    83  		{
    84  			priority: PrimaryNetworkDelegatorBanffPendingPriority,
    85  			expected: true,
    86  		},
    87  		{
    88  			priority: SubnetPermissionlessValidatorPendingPriority,
    89  			expected: true,
    90  		},
    91  		{
    92  			priority: SubnetPermissionlessDelegatorPendingPriority,
    93  			expected: true,
    94  		},
    95  		{
    96  			priority: SubnetPermissionedValidatorPendingPriority,
    97  			expected: true,
    98  		},
    99  		{
   100  			priority: SubnetPermissionedValidatorCurrentPriority,
   101  			expected: false,
   102  		},
   103  		{
   104  			priority: SubnetPermissionlessDelegatorCurrentPriority,
   105  			expected: false,
   106  		},
   107  		{
   108  			priority: SubnetPermissionlessValidatorCurrentPriority,
   109  			expected: false,
   110  		},
   111  		{
   112  			priority: PrimaryNetworkDelegatorCurrentPriority,
   113  			expected: false,
   114  		},
   115  		{
   116  			priority: PrimaryNetworkValidatorCurrentPriority,
   117  			expected: false,
   118  		},
   119  	}
   120  	for _, test := range tests {
   121  		t.Run(fmt.Sprintf("%d", test.priority), func(t *testing.T) {
   122  			require.Equal(t, test.expected, test.priority.IsPending())
   123  		})
   124  	}
   125  }
   126  
   127  func TestPriorityIsValidator(t *testing.T) {
   128  	tests := []struct {
   129  		priority Priority
   130  		expected bool
   131  	}{
   132  		{
   133  			priority: PrimaryNetworkDelegatorApricotPendingPriority,
   134  			expected: false,
   135  		},
   136  		{
   137  			priority: PrimaryNetworkValidatorPendingPriority,
   138  			expected: true,
   139  		},
   140  		{
   141  			priority: PrimaryNetworkDelegatorBanffPendingPriority,
   142  			expected: false,
   143  		},
   144  		{
   145  			priority: SubnetPermissionlessValidatorPendingPriority,
   146  			expected: true,
   147  		},
   148  		{
   149  			priority: SubnetPermissionlessDelegatorPendingPriority,
   150  			expected: false,
   151  		},
   152  		{
   153  			priority: SubnetPermissionedValidatorPendingPriority,
   154  			expected: true,
   155  		},
   156  		{
   157  			priority: SubnetPermissionedValidatorCurrentPriority,
   158  			expected: true,
   159  		},
   160  		{
   161  			priority: SubnetPermissionlessDelegatorCurrentPriority,
   162  			expected: false,
   163  		},
   164  		{
   165  			priority: SubnetPermissionlessValidatorCurrentPriority,
   166  			expected: true,
   167  		},
   168  		{
   169  			priority: PrimaryNetworkDelegatorCurrentPriority,
   170  			expected: false,
   171  		},
   172  		{
   173  			priority: PrimaryNetworkValidatorCurrentPriority,
   174  			expected: true,
   175  		},
   176  	}
   177  	for _, test := range tests {
   178  		t.Run(fmt.Sprintf("%d", test.priority), func(t *testing.T) {
   179  			require.Equal(t, test.expected, test.priority.IsValidator())
   180  		})
   181  	}
   182  }
   183  
   184  func TestPriorityIsPermissionedValidator(t *testing.T) {
   185  	tests := []struct {
   186  		priority Priority
   187  		expected bool
   188  	}{
   189  		{
   190  			priority: PrimaryNetworkDelegatorApricotPendingPriority,
   191  			expected: false,
   192  		},
   193  		{
   194  			priority: PrimaryNetworkValidatorPendingPriority,
   195  			expected: false,
   196  		},
   197  		{
   198  			priority: PrimaryNetworkDelegatorBanffPendingPriority,
   199  			expected: false,
   200  		},
   201  		{
   202  			priority: SubnetPermissionlessValidatorPendingPriority,
   203  			expected: false,
   204  		},
   205  		{
   206  			priority: SubnetPermissionlessDelegatorPendingPriority,
   207  			expected: false,
   208  		},
   209  		{
   210  			priority: SubnetPermissionedValidatorPendingPriority,
   211  			expected: true,
   212  		},
   213  		{
   214  			priority: SubnetPermissionedValidatorCurrentPriority,
   215  			expected: true,
   216  		},
   217  		{
   218  			priority: SubnetPermissionlessDelegatorCurrentPriority,
   219  			expected: false,
   220  		},
   221  		{
   222  			priority: SubnetPermissionlessValidatorCurrentPriority,
   223  			expected: false,
   224  		},
   225  		{
   226  			priority: PrimaryNetworkDelegatorCurrentPriority,
   227  			expected: false,
   228  		},
   229  		{
   230  			priority: PrimaryNetworkValidatorCurrentPriority,
   231  			expected: false,
   232  		},
   233  	}
   234  	for _, test := range tests {
   235  		t.Run(fmt.Sprintf("%d", test.priority), func(t *testing.T) {
   236  			require.Equal(t, test.expected, test.priority.IsPermissionedValidator())
   237  		})
   238  	}
   239  }
   240  
   241  func TestPriorityIsDelegator(t *testing.T) {
   242  	tests := []struct {
   243  		priority Priority
   244  		expected bool
   245  	}{
   246  		{
   247  			priority: PrimaryNetworkDelegatorApricotPendingPriority,
   248  			expected: true,
   249  		},
   250  		{
   251  			priority: PrimaryNetworkValidatorPendingPriority,
   252  			expected: false,
   253  		},
   254  		{
   255  			priority: PrimaryNetworkDelegatorBanffPendingPriority,
   256  			expected: true,
   257  		},
   258  		{
   259  			priority: SubnetPermissionlessValidatorPendingPriority,
   260  			expected: false,
   261  		},
   262  		{
   263  			priority: SubnetPermissionlessDelegatorPendingPriority,
   264  			expected: true,
   265  		},
   266  		{
   267  			priority: SubnetPermissionedValidatorPendingPriority,
   268  			expected: false,
   269  		},
   270  		{
   271  			priority: SubnetPermissionedValidatorCurrentPriority,
   272  			expected: false,
   273  		},
   274  		{
   275  			priority: SubnetPermissionlessDelegatorCurrentPriority,
   276  			expected: true,
   277  		},
   278  		{
   279  			priority: SubnetPermissionlessValidatorCurrentPriority,
   280  			expected: false,
   281  		},
   282  		{
   283  			priority: PrimaryNetworkDelegatorCurrentPriority,
   284  			expected: true,
   285  		},
   286  		{
   287  			priority: PrimaryNetworkValidatorCurrentPriority,
   288  			expected: false,
   289  		},
   290  	}
   291  	for _, test := range tests {
   292  		t.Run(fmt.Sprintf("%d", test.priority), func(t *testing.T) {
   293  			require.Equal(t, test.expected, test.priority.IsDelegator())
   294  		})
   295  	}
   296  }
   297  
   298  func TestPriorityIsCurrentValidator(t *testing.T) {
   299  	tests := []struct {
   300  		priority Priority
   301  		expected bool
   302  	}{
   303  		{
   304  			priority: PrimaryNetworkDelegatorApricotPendingPriority,
   305  			expected: false,
   306  		},
   307  		{
   308  			priority: PrimaryNetworkValidatorPendingPriority,
   309  			expected: false,
   310  		},
   311  		{
   312  			priority: PrimaryNetworkDelegatorBanffPendingPriority,
   313  			expected: false,
   314  		},
   315  		{
   316  			priority: SubnetPermissionlessValidatorPendingPriority,
   317  			expected: false,
   318  		},
   319  		{
   320  			priority: SubnetPermissionlessDelegatorPendingPriority,
   321  			expected: false,
   322  		},
   323  		{
   324  			priority: SubnetPermissionedValidatorPendingPriority,
   325  			expected: false,
   326  		},
   327  		{
   328  			priority: SubnetPermissionedValidatorCurrentPriority,
   329  			expected: true,
   330  		},
   331  		{
   332  			priority: SubnetPermissionlessDelegatorCurrentPriority,
   333  			expected: false,
   334  		},
   335  		{
   336  			priority: SubnetPermissionlessValidatorCurrentPriority,
   337  			expected: true,
   338  		},
   339  		{
   340  			priority: PrimaryNetworkDelegatorCurrentPriority,
   341  			expected: false,
   342  		},
   343  		{
   344  			priority: PrimaryNetworkValidatorCurrentPriority,
   345  			expected: true,
   346  		},
   347  	}
   348  	for _, test := range tests {
   349  		t.Run(fmt.Sprintf("%d", test.priority), func(t *testing.T) {
   350  			require.Equal(t, test.expected, test.priority.IsCurrentValidator())
   351  		})
   352  	}
   353  }
   354  
   355  func TestPriorityIsCurrentDelegator(t *testing.T) {
   356  	tests := []struct {
   357  		priority Priority
   358  		expected bool
   359  	}{
   360  		{
   361  			priority: PrimaryNetworkDelegatorApricotPendingPriority,
   362  			expected: false,
   363  		},
   364  		{
   365  			priority: PrimaryNetworkValidatorPendingPriority,
   366  			expected: false,
   367  		},
   368  		{
   369  			priority: PrimaryNetworkDelegatorBanffPendingPriority,
   370  			expected: false,
   371  		},
   372  		{
   373  			priority: SubnetPermissionlessValidatorPendingPriority,
   374  			expected: false,
   375  		},
   376  		{
   377  			priority: SubnetPermissionlessDelegatorPendingPriority,
   378  			expected: false,
   379  		},
   380  		{
   381  			priority: SubnetPermissionedValidatorPendingPriority,
   382  			expected: false,
   383  		},
   384  		{
   385  			priority: SubnetPermissionedValidatorCurrentPriority,
   386  			expected: false,
   387  		},
   388  		{
   389  			priority: SubnetPermissionlessDelegatorCurrentPriority,
   390  			expected: true,
   391  		},
   392  		{
   393  			priority: SubnetPermissionlessValidatorCurrentPriority,
   394  			expected: false,
   395  		},
   396  		{
   397  			priority: PrimaryNetworkDelegatorCurrentPriority,
   398  			expected: true,
   399  		},
   400  		{
   401  			priority: PrimaryNetworkValidatorCurrentPriority,
   402  			expected: false,
   403  		},
   404  	}
   405  	for _, test := range tests {
   406  		t.Run(fmt.Sprintf("%d", test.priority), func(t *testing.T) {
   407  			require.Equal(t, test.expected, test.priority.IsCurrentDelegator())
   408  		})
   409  	}
   410  }
   411  
   412  func TestPriorityIsPendingValidator(t *testing.T) {
   413  	tests := []struct {
   414  		priority Priority
   415  		expected bool
   416  	}{
   417  		{
   418  			priority: PrimaryNetworkDelegatorApricotPendingPriority,
   419  			expected: false,
   420  		},
   421  		{
   422  			priority: PrimaryNetworkValidatorPendingPriority,
   423  			expected: true,
   424  		},
   425  		{
   426  			priority: PrimaryNetworkDelegatorBanffPendingPriority,
   427  			expected: false,
   428  		},
   429  		{
   430  			priority: SubnetPermissionlessValidatorPendingPriority,
   431  			expected: true,
   432  		},
   433  		{
   434  			priority: SubnetPermissionlessDelegatorPendingPriority,
   435  			expected: false,
   436  		},
   437  		{
   438  			priority: SubnetPermissionedValidatorPendingPriority,
   439  			expected: true,
   440  		},
   441  		{
   442  			priority: SubnetPermissionedValidatorCurrentPriority,
   443  			expected: false,
   444  		},
   445  		{
   446  			priority: SubnetPermissionlessDelegatorCurrentPriority,
   447  			expected: false,
   448  		},
   449  		{
   450  			priority: SubnetPermissionlessValidatorCurrentPriority,
   451  			expected: false,
   452  		},
   453  		{
   454  			priority: PrimaryNetworkDelegatorCurrentPriority,
   455  			expected: false,
   456  		},
   457  		{
   458  			priority: PrimaryNetworkValidatorCurrentPriority,
   459  			expected: false,
   460  		},
   461  	}
   462  	for _, test := range tests {
   463  		t.Run(fmt.Sprintf("%d", test.priority), func(t *testing.T) {
   464  			require.Equal(t, test.expected, test.priority.IsPendingValidator())
   465  		})
   466  	}
   467  }
   468  
   469  func TestPriorityIsPendingDelegator(t *testing.T) {
   470  	tests := []struct {
   471  		priority Priority
   472  		expected bool
   473  	}{
   474  		{
   475  			priority: PrimaryNetworkDelegatorApricotPendingPriority,
   476  			expected: true,
   477  		},
   478  		{
   479  			priority: PrimaryNetworkValidatorPendingPriority,
   480  			expected: false,
   481  		},
   482  		{
   483  			priority: PrimaryNetworkDelegatorBanffPendingPriority,
   484  			expected: true,
   485  		},
   486  		{
   487  			priority: SubnetPermissionlessValidatorPendingPriority,
   488  			expected: false,
   489  		},
   490  		{
   491  			priority: SubnetPermissionlessDelegatorPendingPriority,
   492  			expected: true,
   493  		},
   494  		{
   495  			priority: SubnetPermissionedValidatorPendingPriority,
   496  			expected: false,
   497  		},
   498  		{
   499  			priority: SubnetPermissionedValidatorCurrentPriority,
   500  			expected: false,
   501  		},
   502  		{
   503  			priority: SubnetPermissionlessDelegatorCurrentPriority,
   504  			expected: false,
   505  		},
   506  		{
   507  			priority: SubnetPermissionlessValidatorCurrentPriority,
   508  			expected: false,
   509  		},
   510  		{
   511  			priority: PrimaryNetworkDelegatorCurrentPriority,
   512  			expected: false,
   513  		},
   514  		{
   515  			priority: PrimaryNetworkValidatorCurrentPriority,
   516  			expected: false,
   517  		},
   518  	}
   519  	for _, test := range tests {
   520  		t.Run(fmt.Sprintf("%d", test.priority), func(t *testing.T) {
   521  			require.Equal(t, test.expected, test.priority.IsPendingDelegator())
   522  		})
   523  	}
   524  }