1
0
Fork 0
mirror of https://github.com/eosswedenorg/thalos synced 2026-06-16 04:24:56 +02:00

api/message/msgpack/codec_test.go: Adding test for TransactionTrace

This commit is contained in:
Henrik Hautakoski 2023-05-25 18:47:08 +02:00
parent 3bf62d431a
commit 47dda7a3f4

View file

@ -155,3 +155,166 @@ func TestMsgpack_DecodeHeartbeat(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, expected, msg)
}
func TestMsgpack_EncodeTransactionTrace(t *testing.T) {
tx_id := "edc06dce6320459fd644756972048da453b2816b0a434c37ddffde36778dcab3"
block_num := uint32(2738723781)
ts := time.Unix(1699617279, int64(time.Millisecond)*500).UTC()
msg := message.TransactionTrace{
ID: tx_id,
BlockNum: block_num,
Timestamp: ts,
Status: "soft_fail",
CPUUsageUS: 23,
NetUsageWords: 16,
NetUsage: 128,
Elapsed: 4,
Scheduled: true,
ActionTraces: []message.ActionTrace{
{
Name: "sellitem",
Contract: "skjdh23",
Receiver: "eosio",
Data: map[string]any{
"key": "value",
},
Authorization: []message.PermissionLevel{
{Actor: "actor12123", Permission: "active"},
},
},
{
Name: "sellitem",
Contract: "skjdh24",
Receiver: "eosio",
Authorization: []message.PermissionLevel{
{Actor: "actor1482", Permission: "active"},
},
},
},
Except: "exceptstr",
Error: 2,
}
data, err := encode(msg)
assert.NoError(t, err)
expected := []byte{
0x8c, 0xad, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e,
0x5f, 0x74, 0x72, 0x61, 0x63, 0x65, 0x73, 0x92,
0x8b, 0xad, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72,
0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x91,
0x82, 0xa5, 0x61, 0x63, 0x74, 0x6f, 0x72, 0xaa,
0x61, 0x63, 0x74, 0x6f, 0x72, 0x31, 0x32, 0x31,
0x32, 0x33, 0xaa, 0x70, 0x65, 0x72, 0x6d, 0x69,
0x73, 0x73, 0x69, 0x6f, 0x6e, 0xa6, 0x61, 0x63,
0x74, 0x69, 0x76, 0x65, 0xa8, 0x62, 0x6c, 0x6f,
0x63, 0x6b, 0x6e, 0x75, 0x6d, 0x00, 0xae, 0x62,
0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x69, 0x6d, 0x65,
0x73, 0x74, 0x61, 0x6d, 0x70, 0xc0, 0xa8, 0x63,
0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0xa7,
0x73, 0x6b, 0x6a, 0x64, 0x68, 0x32, 0x33, 0xa4,
0x64, 0x61, 0x74, 0x61, 0x81, 0xa3, 0x6b, 0x65,
0x79, 0xa5, 0x76, 0x61, 0x6c, 0x75, 0x65, 0xa5,
0x65, 0x72, 0x72, 0x6f, 0x72, 0x00, 0xa6, 0x65,
0x78, 0x63, 0x65, 0x70, 0x74, 0xa0, 0xa4, 0x6e,
0x61, 0x6d, 0x65, 0xa8, 0x73, 0x65, 0x6c, 0x6c,
0x69, 0x74, 0x65, 0x6d, 0xa8, 0x72, 0x65, 0x63,
0x65, 0x69, 0x76, 0x65, 0x72, 0xa5, 0x65, 0x6f,
0x73, 0x69, 0x6f, 0xa6, 0x72, 0x65, 0x74, 0x75,
0x72, 0x6e, 0xc0, 0xa5, 0x74, 0x78, 0x5f, 0x69,
0x64, 0xa0, 0x8b, 0xad, 0x61, 0x75, 0x74, 0x68,
0x6f, 0x72, 0x69, 0x7a, 0x61, 0x74, 0x69, 0x6f,
0x6e, 0x91, 0x82, 0xa5, 0x61, 0x63, 0x74, 0x6f,
0x72, 0xa9, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x31,
0x34, 0x38, 0x32, 0xaa, 0x70, 0x65, 0x72, 0x6d,
0x69, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0xa6, 0x61,
0x63, 0x74, 0x69, 0x76, 0x65, 0xa8, 0x62, 0x6c,
0x6f, 0x63, 0x6b, 0x6e, 0x75, 0x6d, 0x00, 0xae,
0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x69, 0x6d,
0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0xc0, 0xa8,
0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74,
0xa7, 0x73, 0x6b, 0x6a, 0x64, 0x68, 0x32, 0x34,
0xa4, 0x64, 0x61, 0x74, 0x61, 0xc0, 0xa5, 0x65,
0x72, 0x72, 0x6f, 0x72, 0x00, 0xa6, 0x65, 0x78,
0x63, 0x65, 0x70, 0x74, 0xa0, 0xa4, 0x6e, 0x61,
0x6d, 0x65, 0xa8, 0x73, 0x65, 0x6c, 0x6c, 0x69,
0x74, 0x65, 0x6d, 0xa8, 0x72, 0x65, 0x63, 0x65,
0x69, 0x76, 0x65, 0x72, 0xa5, 0x65, 0x6f, 0x73,
0x69, 0x6f, 0xa6, 0x72, 0x65, 0x74, 0x75, 0x72,
0x6e, 0xc0, 0xa5, 0x74, 0x78, 0x5f, 0x69, 0x64,
0xa0, 0xa8, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x6e,
0x75, 0x6d, 0xce, 0xa3, 0x3d, 0x9b, 0xc5, 0xae,
0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x74, 0x69, 0x6d,
0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0xd7, 0xff,
0x77, 0x35, 0x94, 0x00, 0x65, 0x4e, 0x19, 0xff,
0xac, 0x63, 0x70, 0x75, 0x5f, 0x75, 0x73, 0x61,
0x67, 0x65, 0x5f, 0x75, 0x73, 0x17, 0xa7, 0x65,
0x6c, 0x61, 0x70, 0x73, 0x65, 0x64, 0x04, 0xa5,
0x65, 0x72, 0x72, 0x6f, 0x72, 0x02, 0xa6, 0x65,
0x78, 0x63, 0x65, 0x70, 0x74, 0xa9, 0x65, 0x78,
0x63, 0x65, 0x70, 0x74, 0x73, 0x74, 0x72, 0xa2,
0x69, 0x64, 0xd9, 0x40, 0x65, 0x64, 0x63, 0x30,
0x36, 0x64, 0x63, 0x65, 0x36, 0x33, 0x32, 0x30,
0x34, 0x35, 0x39, 0x66, 0x64, 0x36, 0x34, 0x34,
0x37, 0x35, 0x36, 0x39, 0x37, 0x32, 0x30, 0x34,
0x38, 0x64, 0x61, 0x34, 0x35, 0x33, 0x62, 0x32,
0x38, 0x31, 0x36, 0x62, 0x30, 0x61, 0x34, 0x33,
0x34, 0x63, 0x33, 0x37, 0x64, 0x64, 0x66, 0x66,
0x64, 0x65, 0x33, 0x36, 0x37, 0x37, 0x38, 0x64,
0x63, 0x61, 0x62, 0x33, 0xa9, 0x6e, 0x65, 0x74,
0x5f, 0x75, 0x73, 0x61, 0x67, 0x65, 0xcc, 0x80,
0xaf, 0x6e, 0x65, 0x74, 0x5f, 0x75, 0x73, 0x61,
0x67, 0x65, 0x5f, 0x77, 0x6f, 0x72, 0x64, 0x73,
0x10, 0xa9, 0x73, 0x63, 0x68, 0x65, 0x64, 0x75,
0x6c, 0x65, 0x64, 0xc3, 0xa6, 0x73, 0x74, 0x61,
0x74, 0x75, 0x73, 0xa9, 0x73, 0x6f, 0x66, 0x74,
0x5f, 0x66, 0x61, 0x69, 0x6c,
}
assert.Equal(t, expected, data)
}
func TestMsgpack_DecodeTransactionTrace(t *testing.T) {
data := []byte("\x8c\xadaction_traces\x91\x8b\xadauthorization\x91\x82\xa5actor\xaaactor12123\xaapermission\xa5claim\xa8blocknum\x00\xaeblocktimestamp\xc0\xa8contract\xa9send.help\xa4data\x81\xa7claimer\xaaactor12123\xa5error\x00\xa6except\xa0\xa4name\xa5claim\xa8receiver\xaaactor12123\xa6return\xc0\xa5tx_id\xa0\xa8blocknumΣ5\x81!\xaeblocktimestamp\xd7\xffw5\x94\x00K\x813̬cpu_usage_us6\xa7elapsed\x04\xa5error+\xa6except\xa9exceptstr\xa2id\xd9@05d7e50e8aa898a84df345f714f741ce804a9cc171da44b893ae74891cc7258a\xa9net_usagè\xafnet_usage_words\x10\xa9scheduledæstatus\xa9hard_fail")
tx_id := "05d7e50e8aa898a84df345f714f741ce804a9cc171da44b893ae74891cc7258a"
block_num := uint32(2738192673)
ts := time.Unix(1266758604, int64(time.Millisecond)*500).UTC()
expected := message.TransactionTrace{
ID: tx_id,
BlockNum: block_num,
Timestamp: ts,
Status: "hard_fail",
CPUUsageUS: 54,
NetUsageWords: 16,
NetUsage: 128,
Elapsed: 4,
Scheduled: true,
ActionTraces: []message.ActionTrace{
{
Name: "claim",
Contract: "send.help",
Receiver: "actor12123",
Data: map[string]any{
"claimer": "actor12123",
},
Authorization: []message.PermissionLevel{
{Actor: "actor12123", Permission: "claim"},
},
},
},
Except: "exceptstr",
Error: 43,
}
// x, _ := encode(expected)
// assert.Equal(t, data, string(x))
res := message.TransactionTrace{}
err := decode(data, &res)
assert.NoError(t, err)
assert.Equal(t, expected, res)
}