func Test_Transaction_MarshalUnMarshal(test *testing.T) { getSignedTrans() // Make sure we have a signed transaction data, err := nb.MarshalBinary() // Marshal our signed transaction if err != nil { // If we have an error, print our stack primitives.Prtln(err) // and fail our test test.Fail() } xb := new(Transaction) err = xb.UnmarshalBinary(data) // Now Unmarshal if err != nil { primitives.Prtln(err) test.Fail() return } // txt1,_ := xb.CustomMarshalText() // txt2,_ := nb.CustomMarshalText() // primitives.Prtln(string(txt1)) // primitives.Prtln(string(txt2)) if xb.IsEqual(nb) != nil { primitives.Prtln("Trans\n", nb, "Unmarshal Trans\n", xb) test.Fail() } }
func Test_Address_MarshalUnMarshal(test *testing.T) { a := nextAddress() adr, err := a.MarshalBinary() if err != nil { primitives.Prtln(err) test.Fail() } _, err = a.UnmarshalBinaryData(adr) if err != nil { primitives.Prtln(err) test.Fail() } }
func Test_SignTransaction_swcallet(test *testing.T) { w := new(SCWallet) // make me a wallet w.Init() w.NewSeed([]byte("lkdfsgjlagkjlasd")) h0, err := w.GenerateFctAddress([]byte("test 0"), 1, 1) if err != nil { test.Fail() } h1, err := w.GenerateFctAddress([]byte("test 1"), 1, 1) if err != nil { test.Fail() } h2, err := w.GenerateFctAddress([]byte("test 2"), 1, 1) if err != nil { test.Fail() } h3, err := w.GenerateFctAddress([]byte("test 3"), 1, 1) if err != nil { test.Fail() } h4, err := w.GenerateFctAddress([]byte("test 4"), 1, 1) if err != nil { test.Fail() } t := w.CreateTransaction(0) w.AddInput(t, h1, 1000000) w.AddInput(t, h2, 1000000) w.AddOutput(t, h3, 1000000) w.AddOutput(t, h4, 1000000) w.AddInput(t, h0, 0) fee, err := t.CalculateFee(1000) w.UpdateInput(t, 2, h0, fee) signed, err := w.SignInputs(t) if !signed || err != nil { primitives.Prtln("Signed Fail: ", signed, err) test.Fail() } //txt, err := t.CustomMarshalText() //primitives.Prtln(string(txt), "\n ", fee) err = w.ValidateSignatures(t) if err != nil { primitives.Prtln(err) test.Fail() } }
func Test_Multisig_MarshalUnMarshal(test *testing.T) { rcd := nextAuth2() auth2, err := rcd.MarshalBinary() if err != nil { primitives.Prtln(err) test.Fail() } _, err = rcd.UnmarshalBinaryData(auth2) if err != nil { primitives.Prtln(err) test.Fail() } }
func Test_CreateTransaction_swcallet(test *testing.T) { w := new(SCWallet) // make me a wallet w.Init() w.NewSeed([]byte("lkdfsgjlagkjlasd")) h1, err := w.GenerateFctAddress([]byte("test 1"), 1, 1) if err != nil { test.Fail() } h2, err := w.GenerateFctAddress([]byte("test 2"), 1, 1) if err != nil { test.Fail() } t := w.CreateTransaction(0) w.AddInput(t, h1, 1000000) w.AddOutput(t, h2, 1000000-12000) signed, err := w.SignInputs(t) if !signed || err != nil { primitives.Prtln("Signed Fail: ", signed, err) test.Fail() } fee, err := t.CalculateFee(1000) if fee != 12000 || err != nil { primitives.Prtln("Fee Calculation Failed", fee, err) test.Fail() } err2 := w.Validate(1, t) if err2 != nil { primitives.Prtln(err2) test.Fail() } }
func Test_create_scwallet(test *testing.T) { w := new(SCWallet) // make me a wallet w.Init() w.NewSeed([]byte("lkdfsgjlagkjlasd")) we := new(WalletEntry) rcd := new(RCD_1) name := "John Smith" pub, pri, err := w.generateKey() if err != nil { primitives.Prtln("Generate Failed") test.Fail() } we.SetRCD(rcd) we.AddKey(pub, pri) we.SetName([]byte(name)) txt, err := we.CustomMarshalText() var _ = txt // primitives.Prtln(string(txt)) }
func Test_create_walletentry(test *testing.T) { w := new(SCWallet) // make me a wallet w.Init() w.NewSeed([]byte("lkdfsgjlagkjlasd")) we := new(WalletEntry) rcd := new(RCD_1) name := "John Smith" adrtype := "fct" pub, pri, err := w.generateKey() if err != nil { primitives.Prtln("Generate Failed") test.Fail() } we.SetRCD(rcd) we.AddKey(pub, pri) we.SetName([]byte(name)) we.SetType(adrtype) data, err := we.MarshalBinary() if err != nil { test.Fail() } w2 := new(WalletEntry) data, err = w2.UnmarshalBinaryData(data) if err != nil { test.Fail() } if we.IsEqual(w2) != nil { test.Fail() } }
func Test_create_block(test *testing.T) { w := new(wallet.SCWallet) // make me a wallet w.Init() w.NewSeed([]byte("slfkjasdlfjasflajsfl")) scb := block.NewFBlock(1000, 0) cb := w.CreateTransaction(uint64(time.Now().UnixNano() / 1000000)) scb.AddCoinbase(cb) for i := 0; i < 3; i++ { h0, err := w.GenerateFctAddress([]byte("test "+cv.Itoa(i)+"-0"), 1, 1) if err != nil { primitives.Prtln("Error 1") test.Fail() } h1, err := w.GenerateFctAddress([]byte("test "+cv.Itoa(i)+"-1"), 1, 1) if err != nil { primitives.Prtln("Error 2") test.Fail() } h2, err := w.GenerateFctAddress([]byte("test "+cv.Itoa(i)+"-2"), 1, 1) if err != nil { primitives.Prtln("Error 3") test.Fail() } h3, err := w.GenerateFctAddress([]byte("test "+cv.Itoa(i)+"-3"), 1, 1) if err != nil { primitives.Prtln("Error 4") test.Fail() } h4, err := w.GenerateFctAddress([]byte("test "+cv.Itoa(i)+"-4"), 1, 1) if err != nil { primitives.Prtln("Error 5") test.Fail() } h5, err := w.GenerateFctAddress([]byte("test "+cv.Itoa(i)+"-5"), 1, 1) if err != nil { primitives.Prtln("Error 6") test.Fail() } t := w.CreateTransaction(uint64(time.Now().UnixNano() / 1000000)) w.AddInput(t, h1, 1000000) w.AddInput(t, h2, 1000000) w.AddOutput(t, h3, 1000000) w.AddOutput(t, h4, 500000) w.AddECOutput(t, h5, 500000) w.AddInput(t, h0, 0) fee, err := t.CalculateFee(1000) w.UpdateInput(t, 2, h0, fee) signed, err := w.SignInputs(t) if err != nil { primitives.Prtln("Error found: ", err) test.Fail() return } if !signed { primitives.Prtln("Not valid") test.Fail() return } err = scb.AddTransaction(t) if err != nil { primitives.Prtln("Error found: ", err) test.Fail() return } } data, err := scb.MarshalBinary() if err != nil { fmt.Println(err) test.Fail() return } scb2 := new(block.FBlock) _, err = scb2.UnmarshalBinaryData(data) fmt.Println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n", scb2) if err != nil { fmt.Println(err) test.Fail() return } //primitives.Prtln("FIRST\n",scb,"SECOND\n",scb2) if scb.IsEqual(scb2) != nil { fmt.Println(err) test.Fail() return } }