This repository has been archived by the owner on Dec 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from Thunnini/supoort-test
Initial support testing
- Loading branch information
Showing
9 changed files
with
343 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
const { | ||
Codec, | ||
TypeFactory, | ||
Utils, | ||
Types, | ||
WireTypes | ||
} = require('../src/index') | ||
const { toHex } = require('./util') | ||
const assert = require('assert') | ||
|
||
describe('Test encode primitive type int', () => { | ||
let codec = new Codec() | ||
const Int8 = TypeFactory.create('Int8', [ | ||
{ | ||
name: 'int8', | ||
type: Types.Int8, | ||
} | ||
], Types.Int8) | ||
|
||
const Int16 = TypeFactory.create('Int16', [ | ||
{ | ||
name: 'int16', | ||
type: Types.Int16, | ||
} | ||
], Types.Int16) | ||
|
||
const Int32 = TypeFactory.create('int32', [ | ||
{ | ||
name: 'int32', | ||
type: Types.Int32, | ||
} | ||
], Types.Int32) | ||
|
||
const Int64 = TypeFactory.create('int64', [ | ||
{ | ||
name: 'int64', | ||
type: Types.Int64, | ||
} | ||
], Types.Int64) | ||
|
||
/* | ||
Encode int8(123) 02f601 | ||
Encode int16(12345) 03f2c001 | ||
Encode int32(1234567) 0387ad4b | ||
Encode int64(123456789) 04959aef3a | ||
*/ | ||
it('result of int8 should match', () => { | ||
let int8 = new Int8(123) | ||
assert.equal(toHex(codec.marshalBinary(int8)), '02f601') | ||
}) | ||
|
||
it('result of int16 should match', () => { | ||
let int16 = new Int16(12345) | ||
assert.equal(toHex(codec.marshalBinary(int16)), '03f2c001') | ||
}) | ||
|
||
it('result of int32 should match', () => { | ||
let int32 = new Int32(1234567) | ||
assert.equal(toHex(codec.marshalBinary(int32)), '0387ad4b') | ||
}) | ||
|
||
it('result of int64 should match', () => { | ||
let int64 = new Int64(123456789) | ||
assert.equal(toHex(codec.marshalBinary(int64)), '04959aef3a') | ||
}) | ||
}) | ||
|
||
|
||
describe('Test encode primitive type string', () => { | ||
let codec = new Codec() | ||
const Str = TypeFactory.create('Str', [ | ||
{ | ||
name: 'str', | ||
type: Types.String, | ||
} | ||
], Types.String) | ||
|
||
/* | ||
Encode string(teststring유니코드) 171674657374737472696e67ec9ca0eb8b88ecbd94eb939c | ||
*/ | ||
it('result of string should match', () => { | ||
let str = new Str('teststring유니코드') | ||
assert.equal(toHex(codec.marshalBinary(str)), '171674657374737472696e67ec9ca0eb8b88ecbd94eb939c') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module github.com/TanNgocDo/Js-Amino/test | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/tendermint/go-amino v0.14.1 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= | ||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
github.com/tendermint/go-amino v0.14.1 h1:o2WudxNfdLNBwMyl2dqOJxiro5rfrEaU0Ugs6offJMk= | ||
github.com/tendermint/go-amino v0.14.1/go.mod h1:i/UKE5Uocn+argJJBb12qTZsCDBcAYMbR92AaJVmKso= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/TanNgocDo/Js-Amino/test" | ||
) | ||
|
||
func main() { | ||
test.PrintPrimitive() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package test | ||
|
||
import ( | ||
"encoding/hex" | ||
"fmt" | ||
|
||
"github.com/tendermint/go-amino" | ||
) | ||
|
||
func PrintPrimitive() { | ||
fmt.Println("test") | ||
|
||
cdc := amino.NewCodec() | ||
|
||
bz := cdc.MustMarshalBinaryLengthPrefixed(int8(123)) | ||
fmt.Println("Encode int8(123)", hex.EncodeToString(bz)) | ||
|
||
bz = cdc.MustMarshalBinaryLengthPrefixed(int16(12345)) | ||
fmt.Println("Encode int16(12345)", hex.EncodeToString(bz)) | ||
|
||
bz = cdc.MustMarshalBinaryLengthPrefixed(int32(1234567)) | ||
fmt.Println("Encode int32(1234567)", hex.EncodeToString(bz)) | ||
|
||
bz = cdc.MustMarshalBinaryLengthPrefixed(int64(123456789)) | ||
fmt.Println("Encode int64(123456789)", hex.EncodeToString(bz)) | ||
|
||
bz = cdc.MustMarshalBinaryLengthPrefixed("teststring유니코드") | ||
fmt.Println("Encode string(teststring유니코드)", hex.EncodeToString(bz)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
To make examples for test in go-amino, we use [go modules](https://github.com/golang/go/wiki/Modules), so you need golang above v1.11 | ||
|
||
To show examples in go-amino, type go run .\main\main.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const toHex = (buffer) => { | ||
let s = '' | ||
buffer.forEach((b) => { | ||
b = b.toString(16) | ||
if (b.length == 1) { | ||
b = '0' + b | ||
} | ||
s += b | ||
}) | ||
return s | ||
} | ||
|
||
module.exports = { | ||
toHex | ||
} |