package blockchain

import "fmt"
import "bytes"
import "testing"
import "encoding/hex"

func Test_RingCT_Full_block_72_2c4738d3856e8e3e8f9fc4818a9197d4911af3010e067ec56d08c264627cb547(t *testing.T){
 
    key_image,_ := hex.DecodeString("b27b6cf2e0dcfc35f2767608cace34e59b1d507d3ef6c5ad7142a1c3aad0d860")
    // this tx is from block 72
    // tx_id 2c4738d3856e8e3e8f9fc4818a9197d4911af3010e067ec56d08c264627cb547
    // it is a ringct full txt 
    tx_hex := "[encoded data, 26098 characters]"
    
    tx_raw,_ :=  hex.DecodeString(tx_hex)
    
    _ = key_image
    
    var tx Transaction
    
    err := tx.DeserializeHeader(tx_raw)
    
    if err != nil {
     t.Errorf("Tx Deserialisation failed")   
    }
    
    // test whether it passes range proof
    
    if tx.RctSignature.VerifyRctFull() != true|| tx.RctSignature.Verify() != true {
        t.Errorf("Tx Range Proof failed") 
    }
    
    
    
}



func Test_RingCT_simple_block_726_2649e0eac5b836ed36b3f4e512824855e222cff7b84652452c769bbed9d06b73(t *testing.T){
 
    key_image1,_ := hex.DecodeString("ea57543450b2b743e729af2daf02c07d65928d25965fec14be1b70464ec2ebf1")
    key_image2,_ := hex.DecodeString("7beed79270b09d389e28307c0360971d0bbc946e16e453d32178ba0c398b88ec")
    // this tx is from block 726
    // tx_id 2649e0eac5b836ed36b3f4e512824855e222cff7b84652452c769bbed9d06b73
    // it is a ringct simple type  TX
    tx_hex := "[encoded data, 27020 characters]"
    
    tx_raw,_ :=  hex.DecodeString(tx_hex)
    
    var tx Transaction
    
    err := tx.DeserializeHeader(tx_raw)
    
    if err != nil {
     t.Errorf("Tx Deserialisation failed")   
    }
    
    tx_bytes := tx.Serialize()
    
    if !bytes.Equal(tx_raw, tx_bytes) {
        t.Errorf("Tx SerDes failed for rct simple tx")
    }
    
    if fmt.Sprintf("%x", tx.GetHash()) != "2649e0eac5b836ed36b3f4e512824855e222cff7b84652452c769bbed9d06b73" {
        t.Errorf("TX hash match failed")
        
    }
    
    _ = key_image1
    _ = key_image2
    
    // test whether it passes range proof
    if tx.RctSignature.VerifyRctSimple() != true || tx.RctSignature.Verify() != true  {
        t.Errorf("Tx Range Proof failed for rct simple tx") 
    }
    
    // BUG BUG ring member for second  vin is decoded incorrectly, we decode it as 76, explorer shows it as 72
    
    
    
}

