github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/chat/flip/simple_test.go (about) 1 package flip 2 3 import ( 4 "fmt" 5 "github.com/stretchr/testify/require" 6 "testing" 7 ) 8 9 func makeTestSecret(b byte) Secret { 10 var ret Secret 11 ret[1] = 0xee 12 ret[0] = b 13 return ret 14 } 15 16 func makeTestPlayer(t *testing.T, cp CommitmentPayload, b byte) PlayerState { 17 s := makeTestSecret(b) 18 c, err := s.computeCommitment(cp) 19 require.NoError(t, err) 20 return PlayerState{ 21 Player: Player(fmt.Sprintf("u%d", b)), 22 Commitment: &c, 23 Reveal: s, 24 } 25 } 26 27 func TestFlip(t *testing.T) { 28 var players []PlayerState 29 cp := CommitmentPayload{} 30 for i := 1; i < 20; i++ { 31 players = append(players, makeTestPlayer(t, cp, byte(i))) 32 } 33 i, err := FlipInt(cp, players, int64(10033)) 34 require.NoError(t, err) 35 require.Equal(t, i, int64(6265)) 36 }