From 18b5914b575ef1d0326aac195c7ff32ec863e89d Mon Sep 17 00:00:00 2001 From: Yaz Khoury Date: Tue, 13 Mar 2018 17:30:24 -0400 Subject: [PATCH 1/4] feat: add initial code for timebound --- build/transaction.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/build/transaction.go b/build/transaction.go index b175c01e70..1d51edd902 100644 --- a/build/transaction.go +++ b/build/transaction.go @@ -256,6 +256,16 @@ func (m MemoText) MutateTransaction(o *TransactionBuilder) (err error) { return } +func (m MinTimeBound) MutateTransaction(o *TransactionBuilder) (err error) { + o.TX.MinTime, err = xdr.NewTimeBound(xdr.MinTime, m.Value) + return +} + +func (m MaxTimeBound) MutateTransaction(o *TransactionBuilder) (err error) { + o.TX.MaxTime, err = xdr.NewTimeBound(xdr.MaxTime, m.Value) + return +} + // MutateTransaction for Network sets the Network ID to use when signing this transaction func (m Network) MutateTransaction(o *TransactionBuilder) error { o.NetworkPassphrase = m.Passphrase From 7242cbcacf7b8e88b81a82b21fddfb8a9a2820d2 Mon Sep 17 00:00:00 2001 From: Yaz Khoury Date: Wed, 14 Mar 2018 16:02:12 -0400 Subject: [PATCH 2/4] feat: add tests and refactor timebounds func --- build/main.go | 5 +++++ build/transaction.go | 12 ++++-------- build/transaction_test.go | 8 ++++++++ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/build/main.go b/build/main.go index f4942cb7b7..2233bbc3ee 100644 --- a/build/main.go +++ b/build/main.go @@ -217,6 +217,11 @@ type Thresholds struct { High *uint32 } +type Timebounds struct { + Mintime uint64 + Maxtime uint64 +} + // Trustor is a mutator capable of setting the trustor on // allow_trust operation. type Trustor struct { diff --git a/build/transaction.go b/build/transaction.go index 1d51edd902..00d361d320 100644 --- a/build/transaction.go +++ b/build/transaction.go @@ -256,14 +256,10 @@ func (m MemoText) MutateTransaction(o *TransactionBuilder) (err error) { return } -func (m MinTimeBound) MutateTransaction(o *TransactionBuilder) (err error) { - o.TX.MinTime, err = xdr.NewTimeBound(xdr.MinTime, m.Value) - return -} - -func (m MaxTimeBound) MutateTransaction(o *TransactionBuilder) (err error) { - o.TX.MaxTime, err = xdr.NewTimeBound(xdr.MaxTime, m.Value) - return +func (m Timebounds) MutateTransaction(o *TransactionBuilder) error { + o.TX.TimeBounds.MinTime = m.Mintime + o.TX.TimeBounds.MaxTime = m.Maxtime + return nil } // MutateTransaction for Network sets the Network ID to use when signing this transaction diff --git a/build/transaction_test.go b/build/transaction_test.go index 22c50dd78c..481bbc7b7c 100644 --- a/build/transaction_test.go +++ b/build/transaction_test.go @@ -111,6 +111,14 @@ var _ = Describe("Transaction Mutators:", func() { }) }) + Describe("Timebounds", func() { + BeforeEach(func() { mut = Timebounds{1521056118, 1521056298} }) + It("sets an minimum and maximum timebound on the transaction", func() { + Expect(subject.TX.TimeBounds.MinTime).To(BeAssignableToTypeOf(xdr.TimeBounds.MinTime)) + Expect(subject.TX.TimeBounds.MaxTime).To(BeAssignableToTypeOf(xdr.TimeBounds.MaxTime)) + }) + }) + Describe("AllowTrustBuilder", func() { BeforeEach(func() { mut = AllowTrust() }) It("adds itself to the tx's operations", func() { From 13fba81de5f921080b81202e266e88a7b20199c5 Mon Sep 17 00:00:00 2001 From: Yaz Khoury Date: Wed, 14 Mar 2018 18:38:50 -0400 Subject: [PATCH 3/4] fix: Instantiate timebounds in mutator, test: Pass all tests --- build/transaction.go | 3 +-- build/transaction_test.go | 5 +++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/build/transaction.go b/build/transaction.go index 00d361d320..e0a7c4b63b 100644 --- a/build/transaction.go +++ b/build/transaction.go @@ -257,8 +257,7 @@ func (m MemoText) MutateTransaction(o *TransactionBuilder) (err error) { } func (m Timebounds) MutateTransaction(o *TransactionBuilder) error { - o.TX.TimeBounds.MinTime = m.Mintime - o.TX.TimeBounds.MaxTime = m.Maxtime + o.TX.TimeBounds = &xdr.TimeBounds{MinTime: xdr.Uint64(m.Mintime), MaxTime: xdr.Uint64(m.Maxtime)} return nil } diff --git a/build/transaction_test.go b/build/transaction_test.go index 481bbc7b7c..c2e6d61dc2 100644 --- a/build/transaction_test.go +++ b/build/transaction_test.go @@ -113,9 +113,10 @@ var _ = Describe("Transaction Mutators:", func() { Describe("Timebounds", func() { BeforeEach(func() { mut = Timebounds{1521056118, 1521056298} }) + It("succeeds", func() { Expect(err).NotTo(HaveOccurred()) }) It("sets an minimum and maximum timebound on the transaction", func() { - Expect(subject.TX.TimeBounds.MinTime).To(BeAssignableToTypeOf(xdr.TimeBounds.MinTime)) - Expect(subject.TX.TimeBounds.MaxTime).To(BeAssignableToTypeOf(xdr.TimeBounds.MaxTime)) + Expect(subject.TX.TimeBounds.MinTime).To(BeEquivalentTo(xdr.Uint64(1521056118))) + Expect(subject.TX.TimeBounds.MaxTime).To(BeEquivalentTo(xdr.Uint64(1521056298))) }) }) From 461593ed0ea4a4f50dda35035057a5ea3d2100b4 Mon Sep 17 00:00:00 2001 From: Yaz Khoury Date: Thu, 15 Mar 2018 14:52:30 -0400 Subject: [PATCH 4/4] refactor: Rename mintime/maxtime, test: Update to use Equal --- build/main.go | 4 ++-- build/transaction.go | 2 +- build/transaction_test.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build/main.go b/build/main.go index 2233bbc3ee..498272e27f 100644 --- a/build/main.go +++ b/build/main.go @@ -218,8 +218,8 @@ type Thresholds struct { } type Timebounds struct { - Mintime uint64 - Maxtime uint64 + MinTime uint64 + MaxTime uint64 } // Trustor is a mutator capable of setting the trustor on diff --git a/build/transaction.go b/build/transaction.go index e0a7c4b63b..538a897670 100644 --- a/build/transaction.go +++ b/build/transaction.go @@ -257,7 +257,7 @@ func (m MemoText) MutateTransaction(o *TransactionBuilder) (err error) { } func (m Timebounds) MutateTransaction(o *TransactionBuilder) error { - o.TX.TimeBounds = &xdr.TimeBounds{MinTime: xdr.Uint64(m.Mintime), MaxTime: xdr.Uint64(m.Maxtime)} + o.TX.TimeBounds = &xdr.TimeBounds{MinTime: xdr.Uint64(m.MinTime), MaxTime: xdr.Uint64(m.MaxTime)} return nil } diff --git a/build/transaction_test.go b/build/transaction_test.go index c2e6d61dc2..144f3c4e8c 100644 --- a/build/transaction_test.go +++ b/build/transaction_test.go @@ -115,8 +115,8 @@ var _ = Describe("Transaction Mutators:", func() { BeforeEach(func() { mut = Timebounds{1521056118, 1521056298} }) It("succeeds", func() { Expect(err).NotTo(HaveOccurred()) }) It("sets an minimum and maximum timebound on the transaction", func() { - Expect(subject.TX.TimeBounds.MinTime).To(BeEquivalentTo(xdr.Uint64(1521056118))) - Expect(subject.TX.TimeBounds.MaxTime).To(BeEquivalentTo(xdr.Uint64(1521056298))) + Expect(subject.TX.TimeBounds.MinTime).To(Equal(xdr.Uint64(1521056118))) + Expect(subject.TX.TimeBounds.MaxTime).To(Equal(xdr.Uint64(1521056298))) }) })