github.com/prysmaticlabs/prysm@v1.4.4/shared/slashutil/double_votes_test.go (about)

     1  package slashutil
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/prysmaticlabs/prysm/shared/params"
     7  )
     8  
     9  func TestSigningRootsDiffer(t *testing.T) {
    10  	type args struct {
    11  		existingSigningRoot [32]byte
    12  		incomingSigningRoot [32]byte
    13  	}
    14  	tests := []struct {
    15  		name string
    16  		args args
    17  		want bool
    18  	}{
    19  		{
    20  			name: "Empty existing signing root is slashable",
    21  			args: args{
    22  				existingSigningRoot: params.BeaconConfig().ZeroHash,
    23  				incomingSigningRoot: [32]byte{1},
    24  			},
    25  			want: true,
    26  		},
    27  		{
    28  			name: "Non-empty, different existing signing root is slashable",
    29  			args: args{
    30  				existingSigningRoot: [32]byte{2},
    31  				incomingSigningRoot: [32]byte{1},
    32  			},
    33  			want: true,
    34  		},
    35  		{
    36  			name: "Non-empty, same existing signing root and incoming signing root is not slashable",
    37  			args: args{
    38  				existingSigningRoot: [32]byte{2},
    39  				incomingSigningRoot: [32]byte{2},
    40  			},
    41  			want: false,
    42  		},
    43  		{
    44  			name: "Both empty are considered slashable",
    45  			args: args{
    46  				existingSigningRoot: params.BeaconConfig().ZeroHash,
    47  				incomingSigningRoot: params.BeaconConfig().ZeroHash,
    48  			},
    49  			want: true,
    50  		},
    51  	}
    52  	for _, tt := range tests {
    53  		t.Run(tt.name, func(t *testing.T) {
    54  			if got := SigningRootsDiffer(tt.args.existingSigningRoot, tt.args.incomingSigningRoot); got != tt.want {
    55  				t.Errorf("SigningRootsDiffer() = %v, want %v", got, tt.want)
    56  			}
    57  		})
    58  	}
    59  }