package tron import "testing" // TestTxIDMatchesPython locks the hand-rolled protobuf encoder to the reference // values produced by tronpy's proto.calculate_txid_from_raw_data. These vectors // were computed with the vendored tronpy 0.6.2 + protobuf runtime. func TestTxIDMatchesPython(t *testing.T) { const baseTS = int64(1600000000000) transfer := &RawData{ Contract: []ContractJSON{{ Parameter: ParameterJSON{ Value: TransferValue{ OwnerAddress: "41ca96b08266d7b36857d8cf2712d449ea07bf0275", ToAddress: "4143d75ee7cdcd7f2fcd4fc3b4eb574b6bdc2a3fcb", Amount: 1000000, }, TypeURL: "type.googleapis.com/protocol.TransferContract", }, Type: "TransferContract", }}, Timestamp: baseTS, Expiration: baseTS + 60000, RefBlockBytes: "1234", RefBlockHash: "1234567890abcdef", } trigger := &RawData{ Contract: []ContractJSON{{ Parameter: ParameterJSON{ Value: TriggerValue{ OwnerAddress: "4143d75ee7cdcd7f2fcd4fc3b4eb574b6bdc2a3fcb", ContractAddress: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t", Data: "a9059cbb000000000000000000000000ca96b08266d7b36857d8cf2712d449ea07bf020000000000000000000000000000000000000000000000000000000000000001", }, TypeURL: "type.googleapis.com/protocol.TriggerSmartContract", }, Type: "TriggerSmartContract", }}, Timestamp: baseTS, Expiration: baseTS + 60000, RefBlockBytes: "1234", RefBlockHash: "1234567890abcdef", FeeLimit: 100000000, } cases := []struct { name string rd *RawData want string }{ {"transfer", transfer, "e93945efde601eed484553338e58218f4e81c51261dfda72db2d874f75378fe8"}, {"trigger", trigger, "0c1dec1fa73590ddf4a3975b78791e72d18998ae42751af199384587c2ef12d0"}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { got, err := tc.rd.TxID() if err != nil { t.Fatalf("TxID: %v", err) } if got != tc.want { t.Fatalf("txid = %s, want %s", got, tc.want) } }) } }