package billing import ( "context" "testing" "time" ) func TestSeedanceActualAmountUsesFrozenTokenPricingAndRoundsUp(t *testing.T) { tests := []struct { resolution string inputVideo bool wantPrice int64 wantAmount int64 }{ {resolution: "720P", wantPrice: 4600, wantAmount: 6}, {resolution: "1080p", inputVideo: true, wantPrice: 3100, wantAmount: 4}, {resolution: "4K", wantPrice: 2600, wantAmount: 4}, } for _, test := range tests { if got := SeedanceTokenPriceFenPerMillion(test.resolution, test.inputVideo); got != test.wantPrice { t.Fatalf("price(%q, %v) = %d, want %d", test.resolution, test.inputVideo, got, test.wantPrice) } got, err := CalculateSeedanceActualAmountFen(SeedanceActualAmountInput{Resolution: test.resolution, InputVideo: test.inputVideo, CompletionTokens: 1001, MarkupMultiplier: 1.2}) if err != nil || got != test.wantAmount { t.Fatalf("amount(%q, %v) = %d, %v; want %d", test.resolution, test.inputVideo, got, err, test.wantAmount) } } } func TestLedgerSettlesSeedanceDeltaWithOneFrozenIdempotencyKey(t *testing.T) { poster := &recordingPoster{result: WalletPosting{LedgerID: "settlement-ledger", CreatedAt: time.Unix(7, 0)}} ledger := Ledger{Poster: poster, NewID: func() string { return "new-ledger" }} posting, err := ledger.Settle(context.Background(), SettlementRequest{ OrganizationID: "org-1", AccountID: "account-1", JobID: "job-1", DeltaFen: 25, Description: "actual usage charge", Metadata: map[string]any{"operation": "seedance_actual_settlement"}, }) if err != nil || posting.LedgerID != "settlement-ledger" { t.Fatalf("posting = %#v, err = %v", posting, err) } if poster.params.Kind != "charge" || poster.params.DeltaFen != -25 || poster.params.IdempotencyKey != "job-settlement:job-1" { t.Fatalf("charge params = %#v", poster.params) } _, err = ledger.Settle(context.Background(), SettlementRequest{OrganizationID: "org-1", JobID: "job-2", DeltaFen: -9}) if err != nil || poster.params.Kind != "refund" || poster.params.DeltaFen != 9 || poster.params.IdempotencyKey != "job-settlement:job-2" { t.Fatalf("refund params = %#v, err = %v", poster.params, err) } }