GetInterchain: perChain + chains options (default first anchor per chain)
Transaction.GetInterchain and Block.GetInterchain take variadic options (client.WithPerChain / client.WithChains, re-exported as sdk.WithPerChain / sdk.WithChains) that map to the new prime-node ?perChain=&chains= query params. Backward compatible: existing no-option calls get the default (one anchor per chain). client.InterchainQuery builds the suffix; unit-tested.
This commit is contained in:
38
transaction/interchain_test.go
Normal file
38
transaction/interchain_test.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package transaction
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
"git.dragonchain.com/dragonchain/prime-sdk-go/client"
|
||||
)
|
||||
|
||||
// TestGetInterchainQuery confirms GetInterchain builds the request URI (path +
|
||||
// the perChain/chains query) end-to-end through the client.
|
||||
func TestGetInterchainQuery(t *testing.T) {
|
||||
var gotURI string
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
gotURI = r.URL.RequestURI()
|
||||
_, _ = io.WriteString(w, `{"blockId":"42","validatorBlocks":[],"interchainTransactions":[]}`)
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
tc := NewTransactionClient(client.NewClient("pid", "kid", "key", srv.URL))
|
||||
|
||||
if _, err := tc.GetInterchain(context.Background(), "tx1", client.WithPerChain(2), client.WithChains("1", "0")); err != nil {
|
||||
t.Fatalf("GetInterchain with opts: %v", err)
|
||||
}
|
||||
if want := "/api/v1/transaction/tx1/interchain?perChain=2&chains=1,0"; gotURI != want {
|
||||
t.Errorf("with opts: URI = %q, want %q", gotURI, want)
|
||||
}
|
||||
|
||||
if _, err := tc.GetInterchain(context.Background(), "tx1"); err != nil {
|
||||
t.Fatalf("GetInterchain default: %v", err)
|
||||
}
|
||||
if want := "/api/v1/transaction/tx1/interchain"; gotURI != want {
|
||||
t.Errorf("default (no opts): URI = %q, want %q", gotURI, want)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user