github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/systests/merkle_client_test.go (about) 1 package systests 2 3 import ( 4 "testing" 5 6 "github.com/keybase/client/go/kbtest" 7 "github.com/keybase/client/go/libkb" 8 "github.com/stretchr/testify/require" 9 ) 10 11 func TestMerkleClientLookups(t *testing.T) { 12 tc := libkb.SetupTest(t, "merkle", 0) 13 defer tc.Cleanup() 14 15 mc := tc.G.GetMerkleClient() 16 17 root, err := mc.FetchRootFromServer(libkb.NewMetaContextForTest(tc), 0) 18 require.NoError(t, err) 19 require.NotNil(t, root) 20 21 tc2 := libkb.SetupTest(t, "merkle", 0) 22 defer tc2.Cleanup() 23 u, err := kbtest.CreateAndSignupFakeUser("mer", tc2.G) 24 require.NoError(t, err) 25 26 q := libkb.NewHTTPArgs() 27 q.Add("uid", libkb.UIDArg(u.GetUID())) 28 29 // Within tc, root is still the one from before the user u was created, so a call without polling should result in a user with no sigchain tail 30 mul, err := mc.LookupUser(libkb.NewMetaContextForTest(tc), q, nil, libkb.MerkleOpts{NoServerPolling: true}) 31 require.NoError(t, err) 32 require.Nil(t, mul.Public()) 33 // Also the merkle root should not have been updated 34 require.Equal(t, *root.Seqno(), *mc.LastRoot(libkb.NewMetaContextForTest(tc)).Seqno()) 35 36 // If we poll, we should receive a user which actually has a sigchain, and the root should be updated in the process 37 mul, err = mc.LookupUser(libkb.NewMetaContextForTest(tc), q, nil, libkb.MerkleOpts{NoServerPolling: false}) 38 require.NoError(t, err) 39 require.NotNil(t, mul.Public()) 40 // Also the merkle root should have been updated 41 newRoot := mc.LastRoot(libkb.NewMetaContextForTest(tc)) 42 require.True(t, *root.Seqno() < *newRoot.Seqno()) 43 44 // Now, let's generate an unrelated merkle tree change to check that polling does not update the root when it's not needed 45 err = tc2.Logout() 46 require.NoError(t, err) 47 _, err = kbtest.CreateAndSignupFakeUser("mer", tc2.G) 48 require.NoError(t, err) 49 // this user creation should have caused the root of the merkle tree to advance 50 require.True(t, *newRoot.Seqno() < *tc2.G.GetMerkleClient().LastRoot(libkb.NewMetaContextForTest(tc2)).Seqno()) 51 52 mul, err = mc.LookupUser(libkb.NewMetaContextForTest(tc), q, nil, libkb.MerkleOpts{NoServerPolling: false}) 53 require.NoError(t, err) 54 require.NotNil(t, mul.Public()) 55 require.Equal(t, *newRoot.Seqno(), *mc.LastRoot(libkb.NewMetaContextForTest(tc)).Seqno()) 56 }