Skip to content

Commit

Permalink
Update TS logic
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Broadhurst <[email protected]>
  • Loading branch information
peterbroadhurst committed Sep 17, 2024
1 parent 026672c commit 2aa170b
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 31 deletions.
3 changes: 1 addition & 2 deletions core/go/internal/statestore/domain_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,8 @@ func (dc *domainContext) mergedUnFlushed(schema Schema, dbStates []*State, query
break
}
}
log.L(dc.ctx).Debugf("Matched in-memory dbLen=%d dbDuplicate=%t stateId=%s createdTS=%d query=%s", len(dbStates), dup, s.ID, &s.CreatedAt, query)
log.L(dc.ctx).Debugf("Matched in-memory dbLen=%d dbDuplicate=%t stateId=%s createdTS=%d query=%s", len(dbStates), dup, &s.ID, s.CreatedAt.UnixNano(), query)
if !dup {
log.L(dc.ctx).Debugf("Matched state %s from un-flushed writes", &s.ID)
matches = append(matches, s)
}
}
Expand Down
2 changes: 2 additions & 0 deletions core/go/internal/statestore/statestore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/DATA-DOG/go-sqlmock"
"github.com/kaleido-io/paladin/core/pkg/persistence"
"github.com/kaleido-io/paladin/core/pkg/persistence/mockpersistence"
"github.com/kaleido-io/paladin/toolkit/pkg/log"
"github.com/stretchr/testify/require"
)

Expand All @@ -39,6 +40,7 @@ func newDBTestStateStore(t *testing.T) (context.Context, *stateStore, func()) {

func newDBMockStateStore(t *testing.T) (context.Context, *stateStore, sqlmock.Sqlmock, func()) {
ctx := context.Background()
log.SetLevel("debug")
p, err := mockpersistence.NewSQLMockProvider()
require.NoError(t, err)
ss := NewStateStore(ctx, &Config{}, p.P)
Expand Down
6 changes: 0 additions & 6 deletions domains/noto/internal/noto/e2e_noto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,3 @@ func TestNotoSelfSubmit(t *testing.T) {
require.NoError(t, err)
assert.Len(t, coins, 4) // TODO: verify coins
}

func TestDecodeError(t *testing.T) {
notoBuild := domain.LoadBuild(notoJSON)
errStr, _ := notoBuild.ABI.ErrorString(tktypes.MustParseHexBytes("0x8b8ff76e7252bf506ebf125cd289ce782a4b4745304a08ff120a23627b8dbd51aa7c8c08"))
assert.Equal(t, `NotoInvalidInput("7252bf506ebf125cd289ce782a4b4745304a08ff120a23627b8dbd51aa7c8c08")`, errStr)
}
19 changes: 5 additions & 14 deletions toolkit/go/pkg/tktypes/timestamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,8 @@ func (ts *Timestamp) Time() time.Time {
return time.Unix(0, (int64)(*ts))
}

func (ts *Timestamp) UnixNano() int64 {
if ts == nil {
return 0
}
return (int64)(*ts)
func (ts Timestamp) UnixNano() int64 {
return (int64)(ts)
}

func (ts *Timestamp) UnmarshalJSON(b []byte) error {
Expand Down Expand Up @@ -122,18 +119,12 @@ func (ts *Timestamp) Scan(src interface{}) error {
}

// Value implements sql.Valuer
func (ts *Timestamp) Value() (driver.Value, error) {
if ts == nil {
return nil, nil
}
if *ts == 0 {
return int64(0), nil
}
func (ts Timestamp) Value() (driver.Value, error) {
return ts.UnixNano(), nil
}

func (ts *Timestamp) String() string {
if ts == nil || *ts == 0 {
func (ts Timestamp) String() string {
if ts == 0 {
return ""
}
return ts.Time().UTC().Format(time.RFC3339Nano)
Expand Down
11 changes: 2 additions & 9 deletions toolkit/go/pkg/tktypes/timestamp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,9 @@ func TestTimestampDatabaseSerialization(t *testing.T) {
now := TimestampNow()
zero := Timestamp(0)

var ts *Timestamp
ts := &zero
v, err := ts.Value()
require.NoError(t, err)
assert.Nil(t, v)

ts = &zero
v, err = ts.Value()
require.NoError(t, err)
assert.Equal(t, int64(0), v)

ts = &now
Expand All @@ -121,10 +116,8 @@ func TestTimestampDatabaseSerialization(t *testing.T) {
}

func TestStringZero(t *testing.T) {
var ts *Timestamp
assert.Equal(t, int64(0), ts.UnixNano())
zero := Timestamp(0)
ts = &zero
ts := &zero
assert.Equal(t, "", ts.String()) // empty string rather than epoch 1970 time
}

Expand Down

0 comments on commit 2aa170b

Please sign in to comment.