5ffd552214
This modifies the block nodes used in the blockchain package for keeping track of the block index to use int64 for the timestamps instead of time.Time. This is being done because a time.Time takes 24 bytes while an int64 only takes 8 and the plan is to eventually move the entire block index into memory instead of the current dynamically-loaded version, so cutting the number of bytes used for the timestamp by a third is highly desirable. Also, the consensus code requires working with unix-style timestamps anyways, so switching over to them in the block node does not seem unreasonable. Finally, this does not go so far as to change all of the time.Time references, particularly those that are in the public API, so it is purely an internal change.
49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
// Copyright (c) 2013-2017 The btcsuite developers
|
|
// Use of this source code is governed by an ISC
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package blockchain_test
|
|
|
|
import (
|
|
"reflect"
|
|
"sort"
|
|
"testing"
|
|
|
|
"github.com/btcsuite/btcd/blockchain"
|
|
)
|
|
|
|
// TestTimeSorter tests the timeSorter implementation.
|
|
func TestTimeSorter(t *testing.T) {
|
|
tests := []struct {
|
|
in []int64
|
|
want []int64
|
|
}{
|
|
{
|
|
in: []int64{
|
|
1351228575, // Fri Oct 26 05:16:15 UTC 2012 (Block #205000)
|
|
1348310759, // Sat Sep 22 10:45:59 UTC 2012 (Block #200000)
|
|
1305758502, // Wed May 18 22:41:42 UTC 2011 (Block #125000)
|
|
1347777156, // Sun Sep 16 06:32:36 UTC 2012 (Block #199000)
|
|
1349492104, // Sat Oct 6 02:55:04 UTC 2012 (Block #202000)
|
|
},
|
|
want: []int64{
|
|
1305758502, // Wed May 18 22:41:42 UTC 2011 (Block #125000)
|
|
1347777156, // Sun Sep 16 06:32:36 UTC 2012 (Block #199000)
|
|
1348310759, // Sat Sep 22 10:45:59 UTC 2012 (Block #200000)
|
|
1349492104, // Sat Oct 6 02:55:04 UTC 2012 (Block #202000)
|
|
1351228575, // Fri Oct 26 05:16:15 UTC 2012 (Block #205000)
|
|
},
|
|
},
|
|
}
|
|
|
|
for i, test := range tests {
|
|
result := make([]int64, len(test.in))
|
|
copy(result, test.in)
|
|
sort.Sort(blockchain.TstTimeSorter(result))
|
|
if !reflect.DeepEqual(result, test.want) {
|
|
t.Errorf("timeSorter #%d got %v want %v", i, result,
|
|
test.want)
|
|
continue
|
|
}
|
|
}
|
|
}
|