forked from calvinlauyh/cosmosutils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tx_test.go
27 lines (21 loc) · 1.06 KB
/
tx_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package cosmosutils_test
import (
"bytes"
"encoding/json"
"github.com/stretchr/testify/assert"
"testing"
"github.com/calvinlauyh/cosmosutils"
)
func TestCosmosTxUnmarshal(t *testing.T) {
anyMsgSendTx := "CpQBCpEBChwvY29zbW9zLmJhbmsudjFiZXRhMS5Nc2dTZW5kEnEKK3Rjcm8xZm1wcm0wc2p5Nmx6OWxsdjdybHRuMHYyYXp6d2N3enZrMmxzeW4SK3Rjcm8xNzgyZ245aHpxYXZlY3VrZGFxcWNsdnNucGNrNG10ejN2d3pweGwaFQoIYmFzZXRjcm8SCTEwMDAwMDAwMBJpClAKRgofL2Nvc21vcy5jcnlwdG8uc2VjcDI1NmsxLlB1YktleRIjCiEDWaFUuiEMSJ2kZiak1jHG+KRxovvaNCFk3V/EoViQHyYSBAoCCH8YBBIVChAKCGJhc2V0Y3JvEgQxMDAwEJBOGkDoEvuh1QEVzd1TTHZ1uDjmznFpzdWtMSGCaWyrt28FuCuVV+4aKEKlV5s2PwpfLkh/ciioH7+B4SXljyZKKdoH"
decoder := cosmosutils.DefaultDecoder
tx, err := decoder.DecodeBase64(anyMsgSendTx)
assert.NoError(t, err)
jsonBytes, err := tx.MarshalToJSON()
assert.NoError(t, err)
var cosmosTx *cosmosutils.CosmosTx
jsonDecoder := json.NewDecoder(bytes.NewReader(jsonBytes))
jsonDecoder.DisallowUnknownFields()
jsonDecodeErr := jsonDecoder.Decode(&cosmosTx)
assert.NoError(t, jsonDecodeErr)
}