func NewAccount(t *testing.T) { groupPrivateKey, err := bbssig.GenerateGroup(rand.Reader) if err != nil { t.Fatal(err) } oneShotTest(t, &pond.Request{ NewAccount: &pond.NewAccount{ Generation: proto.Uint32(0), Group: groupPrivateKey.Group.Marshal(), }, }, func(t *testing.T, reply *pond.Reply) { if reply.AccountCreated == nil { t.Errorf("Bad reply to new account: %s", reply) } }) }
func runScript(t *testing.T, s script) { server := NewTestServer() defer server.Close() identities := make([][32]byte, s.numPlayers) publicIdentities := make([][32]byte, s.numPlayers) for i := range identities { io.ReadFull(rand.Reader, identities[i][:]) curve25519.ScalarBaseMult(&publicIdentities[i], &identities[i]) } groupPrivateKeys := make([]*bbssig.PrivateKey, s.numPlayersWithAccounts) for i := range groupPrivateKeys { var err error groupPrivateKeys[i], err = bbssig.GenerateGroup(rand.Reader) if err != nil { panic(err) } conn := server.Dial(&identities[i], &publicIdentities[i]) if err := conn.Write(&pond.Request{ NewAccount: &pond.NewAccount{ Generation: proto.Uint32(0), Group: groupPrivateKeys[i].Group.Marshal(), }, }); err != nil { t.Fatal(err) } reply := new(pond.Reply) if err := conn.Read(reply); err != nil { t.Fatalf("Error while reading reply from server: %s", err) } if reply.AccountCreated == nil { t.Fatalf("Failed to create 1st account: %s", err) } conn.Close() } state := &scriptState{ identities: identities, publicIdentities: publicIdentities, groupPrivateKeys: groupPrivateKeys, } for _, a := range s.actions { conn := server.Dial(&identities[a.player], &publicIdentities[a.player]) req := a.request if a.buildRequest != nil { req = a.buildRequest(state) } if err := conn.Write(req); err != nil { t.Fatal(err) } reply := new(pond.Reply) if err := conn.Read(reply); err != nil { t.Fatal(err) } a.validate(t, reply) conn.Close() } }