Skip to content

Commit

Permalink
chore: small unittest to test that generated models.Error has its Rea…
Browse files Browse the repository at this point in the history
…son automatically dereferenced when printing it
  • Loading branch information
randomshinichi committed Apr 30, 2019
1 parent 14ce6ed commit 839c5b2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
21 changes: 21 additions & 0 deletions generated_test/error_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package generated_test

import (
"fmt"
"strings"
"testing"

"github.com/aeternity/aepp-sdk-go/generated/client/external"
"github.com/aeternity/aepp-sdk-go/generated/models"
)

func TestErrorModelDereferencing(t *testing.T) {
reason := "A Very Good Reason"
postTransactionBadRequest := external.NewPostTransactionBadRequest()
err := models.Error{Reason: &reason}
postTransactionBadRequest.Payload = &err
printedError := fmt.Sprintf("BadRequest %s", postTransactionBadRequest)
if !strings.Contains(printedError, reason) {
t.Errorf("Expected to find %s when printing out the models.Error: got %s instead", reason, printedError)
}
}
3 changes: 1 addition & 2 deletions generated_test/generic_txs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import (
"github.com/aeternity/aepp-sdk-go/generated/models"
)

// Unfortunately, one must modify the generated go-swagger code.

// Unfortunately, one must patch the generated go-swagger code to correctly parse the GenericTx into a specific Transaction type.
// Ideally the test JSON snippet should include every possible transaction type, but it only tests SpendTx for now.
func TestGenericTxsPolymorphicDeserialization(t *testing.T) {
genericTxsJSON := []byte("{\"transactions\":[{\"block_hash\":\"mh_qoxFYgZoG7NxocZqBk1Dx9DJZKboT9WCKGFWV26QHKhB3oPDp\",\"block_height\":8835,\"hash\":\"th_uRnWPL3iqiLB7MzsVQ3aAgHsFALd62cmcNkw7ea1n9sfXybcr\",\"signatures\":[\"sg_RBq5vRuRchZ26HCPnZk5Xorn3ooQtfZSxf4mEPCsnpV9UD9KuZvqEKHM3vosoVvCvxvF5CyfdDkzCHnYW8bs3Ai7EtMBY\"],\"tx\":{\"amount\":10,\"fee\":20000000000000,\"nonce\":54,\"payload\":\"Hello World\",\"recipient_id\":\"ak_Egp9yVdpxmvAfQ7vsXGvpnyfNq71msbdUpkMNYGTeTe8kPL3v\",\"sender_id\":\"ak_2a1j2Mk9YSmC1gioUq4PWRm3bsv887MbuRVwyv4KaUGoR1eiKi\",\"ttl\":9335,\"type\":\"SpendTx\",\"version\":1}}]}")
Expand Down

0 comments on commit 839c5b2

Please sign in to comment.