func TestRouteEnvelopeToPeerAgent(t *testing.T) {

	rxEnvelopesPeer := make(chan *aea.Envelope, 2)
	dhtPeer, cleanup, err := dhttests.NewDHTPeerWithDefaults(rxEnvelopesPeer)
	if err != nil {
		t.Fatal("Failed to create DHTPeer (required for DHTClient):", err)
	}
	defer cleanup()

	signature, err := utils.SignFetchAI([]byte(DefaultFetchAIPublicKey), DefaultAgentKey)
	if err != nil {
		t.Fatal("Failed to initialize DHTClient:", err)
	}

	record := &acn.AgentRecord{LedgerId: DefaultLedger}
	record.Address = DefaultAgentAddress
	record.PublicKey = DefaultAgentPublicKey
	record.PeerPublicKey = DefaultFetchAIPublicKey
	record.Signature = signature

	opts := []Option{
		IdentityFromFetchAIKey(DefaultFetchAIKey),
		RegisterAgentAddress(record, func() bool { return true }),
		BootstrapFrom([]string{dhtPeer.MultiAddr()}),
	}

	t.Log(dhtPeer.MultiAddr())

	dhtClient, err := New(opts...)
	if err != nil {
		t.Fatal("Failed to initialize DHTClient:", err)
	}
	defer dhtClient.Close()

	rxEnvelopesClient := make(chan *aea.Envelope, 2)
	dhtClient.ProcessEnvelope(func(envel *aea.Envelope) error {
		rxEnvelopesClient <- envel
		return nil
	})

	if len(rxEnvelopesPeer) != 0 {
		t.Error("DHTPeer agent inbox should be empty")
	}

	err = dhtClient.RouteEnvelope(&aea.Envelope{
		To:     dhttests.DHTPeerDefaultAgentAddress,
		Sender: DefaultAgentAddress,
	})
	if err != nil {
		t.Error("Failed to Route envelope to DHTPeer agent:", err)
	}

	timeout := time.After(EnvelopeDeliveryTimeout)
	select {
	case envel := <-rxEnvelopesPeer:
		t.Log("DHT received envelope", envel)
	case <-timeout:
		t.Error("Failed to Route envelope to DHTPeer agent")
	}

}
// TestRouteEnvelopeToPeerAgent send envelope from DHTClient agent to DHTPeer agent
TestRouteEnvelopeToPeerAgent send envelope from DHTClient agent to DHTPeer agent
// TestRouteEnvelopeToPeerAgent send envelope from DHTClient agent to DHTPeer agent
func TestRouteEnvelopeToPeerAgent(t *testing.T) {
	rxEnvelopesPeer := make(chan *aea.Envelope, 2)
	dhtPeer, cleanup, err := dhttests.NewDHTPeerWithDefaults(rxEnvelopesPeer)
	if err != nil {
		t.Fatal("Failed to create DHTPeer (required for DHTClient):", err)
	}
	defer cleanup()
	signature, err := utils.SignFetchAI([]byte(DefaultFetchAIPublicKey), DefaultAgentKey)
	if err != nil {
		t.Fatal("Failed to initialize DHTClient:", err)
	}
	record := &acn.AgentRecord{LedgerId: DefaultLedger}
	record.Address = DefaultAgentAddress
	record.PublicKey = DefaultAgentPublicKey
	record.PeerPublicKey = DefaultFetchAIPublicKey
	record.Signature = signature
	opts := []Option{
		IdentityFromFetchAIKey(DefaultFetchAIKey),
		RegisterAgentAddress(record, func() bool { return true }),
		BootstrapFrom([]string{dhtPeer.MultiAddr()}),
	}
	t.Log(dhtPeer.MultiAddr())
	dhtClient, err := New(opts...)
	if err != nil {
		t.Fatal("Failed to initialize DHTClient:", err)
	}
	defer dhtClient.Close()
	rxEnvelopesClient := make(chan *aea.Envelope, 2)
	dhtClient.ProcessEnvelope(func(envel *aea.Envelope) error {
		rxEnvelopesClient <- envel
		return nil
	})
	if len(rxEnvelopesPeer) != 0 {
		t.Error("DHTPeer agent inbox should be empty")
	}
	err = dhtClient.RouteEnvelope(&aea.Envelope{
		To:     dhttests.DHTPeerDefaultAgentAddress,
		Sender: DefaultAgentAddress,
	})
	if err != nil {
		t.Error("Failed to Route envelope to DHTPeer agent:", err)
	}
	timeout := time.After(EnvelopeDeliveryTimeout)
	select {
	case envel := <-rxEnvelopesPeer:
		t.Log("DHT received envelope", envel)
	case <-timeout:
		t.Error("Failed to Route envelope to DHTPeer agent")
	}
}
func TestRouteEnvelopeToPeerAgent ( t * testing . T ) { rxEnvelopesPeer := make ( chan * aea . Envelope , 2 ) dhtPeer , cleanup , err := dhttests . NewDHTPeerWithDefaults ( rxEnvelopesPeer ) if err != nil { t . Fatal ( " " , err ) } defer cleanup ( ) signature , err := utils . SignFetchAI ( [ ] byte ( DefaultFetchAIPublicKey ) , DefaultAgentKey ) if err != nil { t . Fatal ( " " , err ) } record := & acn . AgentRecord { LedgerId : DefaultLedger } record . Address = DefaultAgentAddress record . PublicKey = DefaultAgentPublicKey record . PeerPublicKey = DefaultFetchAIPublicKey record . Signature = signature opts := [ ] Option { IdentityFromFetchAIKey ( DefaultFetchAIKey ) , RegisterAgentAddress ( record , func ( ) bool { return true } ) , BootstrapFrom ( [ ] string { dhtPeer . MultiAddr ( ) } ) , } t . Log ( dhtPeer . MultiAddr ( ) ) dhtClient , err := New ( opts ... ) if err != nil { t . Fatal ( " " , err ) } defer dhtClient . Close ( ) rxEnvelopesClient := make ( chan * aea . Envelope , 2 ) dhtClient . ProcessEnvelope ( func ( envel * aea . Envelope ) error { rxEnvelopesClient <- envel return nil } ) if len ( rxEnvelopesPeer ) != 0 { t . Error ( " " ) } err = dhtClient . RouteEnvelope ( & aea . Envelope { To : dhttests . DHTPeerDefaultAgentAddress , Sender : DefaultAgentAddress , } ) if err != nil { t . Error ( " " , err ) } timeout := time . After ( EnvelopeDeliveryTimeout ) select { case envel := <- rxEnvelopesPeer : t . Log ( " " , envel ) case <- timeout : t . Error ( " " ) } }
TestRouteEnvelopeToPeerAgent send envelope from DHTClient agent to DHTPeer agent
TestRouteEnvelopeToPeerAgent send envelope from DHTClient agent to DHTPeer agent