func TestAppendOrder(t *testing.T) { is := is.New(t) byteData := [4][]byte{ {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 58}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0d, 0x24}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0xfa, 0x28}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xac, 0xad, 0x10}, } expectedIDs := [4]string{ `c41111111111111111111111111111111111111111111111111111111111111111111111111111111111111121`, `c41111111111111111111111111111111111111111111111111111111111111111111111111111111111111211`, `c41111111111111111111111111111111111111111111111111111111111111111111111111111111111112111`, `c41111111111111111111111111111111111111111111111111111111111111111111111111111111111121111`, } for k := 0; k < 4; k++ { b := byteData[k] bignum := big.NewInt(0) bignum = bignum.SetBytes(b) id := asset.ID(*bignum) is.Equal(id.String(), expectedIDs[k]) id2, err := asset.ParseID(expectedIDs[k]) is.NoErr(err) bignum2 := big.Int(*id2) b = (&bignum2).Bytes() size := len(b) for size < 64 { b = append([]byte{0}, b...) size++ } for i, bb := range b { is.Equal(bb, byteData[k][i]) } } }
func TestRawBytes(t *testing.T) { is := is.New(t) // var b []byte // for i := 0; i < 64; i++ { // b = append(b, 0xFF) // } // id := asset.BytesToID(b) // is.Equal(id.String(), `c467RPWkcUr5dga8jgywjSup7CMoA9FNqkNjEFgAkEpF9vNktFnx77e2Js11EDL3BNu9MaKFUbacZRt1HYym4b8RNp`) // id2, err := asset.ParseID(`c41111111111111111111111111111111111111111111111111111111111111111111111111111111111111121`) // tb2 := []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 58} // is.NoErr(err) // b2 := id2.RawBytes() // fmt.Println("tb2: ", tb2) // fmt.Println("b2: ", b2) // for i, bb := range b2 { // is.Equal(bb, tb2[i]) // } for _, test := range []struct { Bytes []byte IdStr string }{ { Bytes: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 58}, IdStr: `c41111111111111111111111111111111111111111111111111111111111111111111111111111111111111121`, }, { Bytes: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x0d, 0x24}, IdStr: `c41111111111111111111111111111111111111111111111111111111111111111111111111111111111111211`, }, { Bytes: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0xfa, 0x28}, IdStr: `c41111111111111111111111111111111111111111111111111111111111111111111111111111111111112111`, }, { Bytes: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xac, 0xad, 0x10}, IdStr: `c41111111111111111111111111111111111111111111111111111111111111111111111111111111111121111`, }, } { id, err := asset.ParseID(test.IdStr) is.NoErr(err) for i, bb := range id.RawBytes() { is.Equal(bb, test.Bytes[i]) } } }
func TestAllFFFF(t *testing.T) { is := is.New(t) var b []byte for i := 0; i < 64; i++ { b = append(b, 0xFF) } bignum := big.NewInt(0) bignum = bignum.SetBytes(b) id := asset.ID(*bignum) is.Equal(id.String(), `c467RPWkcUr5dga8jgywjSup7CMoA9FNqkNjEFgAkEpF9vNktFnx77e2Js11EDL3BNu9MaKFUbacZRt1HYym4b8RNp`) id2, err := asset.ParseID(`c467RPWkcUr5dga8jgywjSup7CMoA9FNqkNjEFgAkEpF9vNktFnx77e2Js11EDL3BNu9MaKFUbacZRt1HYym4b8RNp`) is.NoErr(err) bignum2 := big.Int(*id2) b = (&bignum2).Bytes() for _, bb := range b { is.Equal(bb, 0xFF) } }
func TestAll0000(t *testing.T) { is := is.New(t) var b []byte for i := 0; i < 64; i++ { b = append(b, 0x00) } bignum := big.NewInt(0) bignum = bignum.SetBytes(b) id := asset.ID(*bignum) is.Equal(id.String(), `c41111111111111111111111111111111111111111111111111111111111111111111111111111111111111111`) id2, err := asset.ParseID(`c41111111111111111111111111111111111111111111111111111111111111111111111111111111111111111`) is.NoErr(err) bignum2 := big.Int(*id2) b = (&bignum2).Bytes() // This loop is unnecessary, bignum zero has only 1 byte. for _, bb := range b { is.Equal(bb, 0x00) } }