CSP3ROTU3KQQBKKDKY7WYBTBHM5DY3QOVKYFHMDTLXVMAZG3IHQAC
WQWRJHHFIZPMIZBDFZGOVTGSQRSIJP275I5MFSGLAR63FJQ4PQJQC
6GDPWAD2BSPC6EDH43HDTFRJ2QCDBPE3OK4KXFVYK23BLCAWWB3QC
7VEHGTEYCNDRXUT7BV5BVNO6SKE3QRYC324Y4DMUPYVVVEOXMETAC
PHRWK7NKNWEVKPVM7WESHMWWRABBURJE7ITAESPYFFI4GYIDXDMQC
FBQT4QEBOCEVB3DZKVRUDWW4TUHG27JEQIDHN67D2PD6WQGRTSXQC
4JWXOJIPJAOL6FZMQENB2ZUTWEFXNB7VU2NHYDNT4T45ESSCSUPQC
EVHNGDT7VJI377HHBZ4XSJCGKFCMJUELJ4APYQVDPBAK6RNIC6AAC
var CB7A3P_golden = Change{
Version: 6,
Message: "Say hello",
Description: "a trivial change",
Timestamp: time.Date(2023, 3, 27, 18, 51, 58, 26097601, time.UTC),
Authors: []map[string]string{
{
"key": "BCEXYuKWaQ96btsk8UyBZWHLjn1Brhykv8tuZGPRjzFn",
},
},
Dependencies: []Hash{Hash{0xe7, 0x82, 0xb1, 0xd7, 0xe4, 0x17, 0x64, 0xe4, 0xfe, 0x45, 0x2d, 0x6f, 0x24, 0x22, 0x40, 0x26, 0x16, 0x12, 0xb7, 0xf, 0x42, 0x70, 0xd9, 0xac, 0xd8, 0x4e, 0x5a, 0x82, 0xea, 0x85, 0xab, 0x57}},
ExtraKnown: []Hash{},
Metadata: []byte{},
Changes: []Hunk{
FileAdd{
AddName: NewVertex{
UpContext: []Position{
Position{
Change: OptionalHash{true, Hash{0xe7, 0x82, 0xb1, 0xd7, 0xe4, 0x17, 0x64, 0xe4, 0xfe, 0x45, 0x2d, 0x6f, 0x24, 0x22, 0x40, 0x26, 0x16, 0x12, 0xb7, 0x0f, 0x42, 0x70, 0xd9, 0xac, 0xd8, 0x4e, 0x5a, 0x82, 0xea, 0x85, 0xab, 0x57}},
Pos: 0x1,
},
var changeTestCases = []struct {
hash string
data []byte
parsed Change
}{
{
hash: "CB7A3PP3XC6JY3QYUUNB4WCXGNFJMHTTH54MBAWBUVQL7TTHWBBQC",
data: CB7A3P,
parsed: Change{
Version: 6,
Message: "Say hello",
Description: "a trivial change",
Timestamp: time.Date(2023, 3, 27, 18, 51, 58, 26097601, time.UTC),
Authors: []map[string]string{
{
"key": "BCEXYuKWaQ96btsk8UyBZWHLjn1Brhykv8tuZGPRjzFn",
AddInode: NewVertex{
UpContext: []Position{
Position{
Change: OptionalHash{},
Pos: 0x1d,
Dependencies: []Hash{Hash{0xe7, 0x82, 0xb1, 0xd7, 0xe4, 0x17, 0x64, 0xe4, 0xfe, 0x45, 0x2d, 0x6f, 0x24, 0x22, 0x40, 0x26, 0x16, 0x12, 0xb7, 0xf, 0x42, 0x70, 0xd9, 0xac, 0xd8, 0x4e, 0x5a, 0x82, 0xea, 0x85, 0xab, 0x57}},
ExtraKnown: []Hash{},
Metadata: []byte{},
Changes: []Hunk{
FileAdd{
AddName: NewVertex{
UpContext: []Position{
Position{
Change: OptionalHash{true, Hash{0xe7, 0x82, 0xb1, 0xd7, 0xe4, 0x17, 0x64, 0xe4, 0xfe, 0x45, 0x2d, 0x6f, 0x24, 0x22, 0x40, 0x26, 0x16, 0x12, 0xb7, 0x0f, 0x42, 0x70, 0xd9, 0xac, 0xd8, 0x4e, 0x5a, 0x82, 0xea, 0x85, 0xab, 0x57}},
Pos: 0x1,
},
},
DownContext: []Position{},
Flag: 0x11,
Start: 0x0,
End: 0x1d,
Inode: Position{
Change: OptionalHash{true, Hash{}},
Pos: 0x0,
},
},
DownContext: []Position{},
Flag: 0x11,
Start: 0x1e,
End: 0x1e,
Inode: Position{
Change: OptionalHash{true, Hash{}},
Pos: 0x0,
},
},
Contents: NewVertex{
UpContext: []Position{
Position{
Change: OptionalHash{},
Pos: 0x1e,
AddInode: NewVertex{
UpContext: []Position{
Position{
Change: OptionalHash{},
Pos: 0x1d,
},
},
DownContext: []Position{},
Flag: 0x11,
Start: 0x1e,
End: 0x1e,
Inode: Position{
Change: OptionalHash{true, Hash{}},
Pos: 0x0,
},
},
Contents: NewVertex{
UpContext: []Position{
Position{
Change: OptionalHash{},
Pos: 0x1e,
},
},
DownContext: []Position{},
Flag: 0x1,
Start: 0x1f,
End: 0x2c,
Inode: Position{
Change: OptionalHash{},
Pos: 0x1e,
},
DownContext: []Position{},
Flag: 0x1,
Start: 0x1f,
End: 0x2c,
Inode: Position{
Change: OptionalHash{},
Pos: 0x1e,
},
},
ContentsHash: Hash{0x9e, 0xb3, 0xf7, 0x5c, 0x66, 0x9f, 0x18, 0xec, 0x4f, 0xf7, 0x30, 0x51, 0x42, 0xfe, 0x79, 0xbd, 0x52, 0x87, 0x24, 0x1, 0x1a, 0xc5, 0x77, 0xe8, 0xf9, 0x5b, 0x14, 0xd9, 0xee, 0xf7, 0x21, 0x48},
Unhashed: map[string]any{
"signature": "4cKLG1A2wd3pp6hBMaceFCGo8ADhUaDNz31MJeZxNFYnBf8yPepXfgor9o78y88ComC3b1YzDccucDbPbez9Ppxe",
Path: "hello",
Encoding: "UTF-8",
Contents: []byte{
0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x01,
0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0x54, 0x46, 0x2d, 0x38, 0x00, 0x00, 0x68,
0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x0a, 0x00,
},
},
ContentsHash: Hash{0x9e, 0xb3, 0xf7, 0x5c, 0x66, 0x9f, 0x18, 0xec, 0x4f, 0xf7, 0x30, 0x51, 0x42, 0xfe, 0x79, 0xbd, 0x52, 0x87, 0x24, 0x1, 0x1a, 0xc5, 0x77, 0xe8, 0xf9, 0x5b, 0x14, 0xd9, 0xee, 0xf7, 0x21, 0x48},
Unhashed: map[string]any{
"signature": "4cKLG1A2wd3pp6hBMaceFCGo8ADhUaDNz31MJeZxNFYnBf8yPepXfgor9o78y88ComC3b1YzDccucDbPbez9Ppxe",
},
Contents: []byte{
0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x01,
0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x55, 0x54, 0x46, 0x2d, 0x38, 0x00, 0x00, 0x68,
0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x0a, 0x00,
c, err := DeserializeChange(CB7A3P)
if err != nil {
t.Fatalf("deserialization error: %v", err)
}
if !reflect.DeepEqual(c, CB7A3P_golden) {
t.Fatalf("got %s, want %s", spew.Sdump(c), spew.Sdump(CB7A3P_golden))
for _, testCase := range changeTestCases {
c, err := DeserializeChange(testCase.data)
if err != nil {
t.Errorf("%s: deserialization error: %v", testCase.hash, err)
continue
}
if !reflect.DeepEqual(c, testCase.parsed) {
t.Errorf("%s: got %s, want %s", testCase.hash, spew.Sdump(c), spew.Sdump(testCase.parsed))
}