aboutsummaryrefslogtreecommitdiff
path: root/auction_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'auction_test.go')
-rw-r--r--auction_test.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/auction_test.go b/auction_test.go
index 04c2590..5f2b3e1 100644
--- a/auction_test.go
+++ b/auction_test.go
@@ -2,7 +2,11 @@ package seal
import (
"encoding/json"
+ "fmt"
+ "log/slog"
+ "math/rand"
"strings"
+ "sync"
"testing"
"time"
)
@@ -34,3 +38,60 @@ func TestParseDescription(t *testing.T) {
t.Fatalf("expected bitlength %d, but got: %d", 8, d.Bitlength)
}
}
+
+type bidder struct {
+ bid uint64
+}
+
+func (b *bidder) Broadcast(m Message) error {
+ return fmt.Errorf("Broadcast not implemented")
+}
+
+func (b *bidder) Result(r Result) {
+ fmt.Printf("got result: %v\n", r)
+}
+
+func (b *bidder) Start() error {
+ return fmt.Errorf("bidder start not fully implemented")
+}
+
+func TestAuction(t *testing.T) {
+ var bidders [10]struct {
+ b bidder
+ a Auction
+ }
+ d := Description{
+ Start: time.Now(),
+ End: time.Now().Add(time.Hour),
+ Timeout: Duration(time.Minute),
+ Bitlength: 8,
+ Type: TypHighest,
+ Seller: nil,
+ }
+
+ for i := range bidders {
+ bidders[i].b.bid = rand.Uint64() & 0xFF
+ a, e := Join(&bidders[i].b, &d)
+ if e != nil {
+ t.Fatal(e)
+ }
+ if e != nil {
+ t.Fatal(e)
+ }
+ bidders[i].a = a
+ }
+
+ var wg sync.WaitGroup
+
+ wg.Add(len(bidders))
+ for i, b := range bidders {
+ go func() {
+ e := b.a.Start()
+ if e != nil {
+ (b.a.(*auction)).log.Error(e.Error(), slog.Int("id", i), slog.Uint64("bid", b.b.bid))
+ }
+ wg.Done()
+ }()
+ }
+ wg.Wait()
+}