From 48bbd93a619dfc73125cdd52262a116459134b86 Mon Sep 17 00:00:00 2001 From: Henrique Santos Date: Fri, 26 Dec 2025 03:01:48 -0300 Subject: [PATCH] fix: update withdraw amount to reflect fee deduction in issuance tests --- cmd/tribes-dcm/root/root.go | 7 +- docs/configs.md | 2 +- go.mod | 2 +- go.sum | 4 +- internal/domain/entity/issuance.go | 20 +- internal/domain/entity/order.go | 24 +-- internal/domain/entity/user.go | 8 +- internal/infra/repository/repository.go | 13 +- internal/infra/repository/sqlite/issuance.go | 44 ++-- internal/infra/repository/sqlite/order.go | 4 +- internal/infra/repository/sqlite/sqlite.go | 12 +- internal/infra/repository/sqlite/user.go | 6 +- .../infra/rollup/handler/advance/issuance.go | 16 +- internal/infra/rollup/handler/advance/user.go | 4 +- internal/infra/rollup/middleware/rbac.go | 8 +- internal/usecase/issuance/close_issuance.go | 56 +++--- internal/usecase/issuance/create_issuance.go | 40 ++-- .../issuance/execute_issuance_collateral.go | 18 +- .../find_issuance_by_creator_address.go | 4 +- .../find_issuance_by_investor_address.go | 4 +- internal/usecase/issuance/general_dto.go | 8 +- internal/usecase/issuance/settle_issuance.go | 21 +- internal/usecase/order/cancel_order.go | 6 +- internal/usecase/order/create_order.go | 7 +- .../order/find_orders_by_investor_address.go | 4 +- .../social_account/create_social_account.go | 8 +- internal/usecase/user/create_user.go | 8 +- .../usecase/user/delete_user_by_address.go | 4 +- internal/usecase/user/find_user_by_address.go | 4 +- internal/usecase/user/general_dto.go | 8 +- internal/usecase/user/withdraw.go | 12 +- test/integration/issuance.test.ts | 32 +-- test/integration/order.test.ts | 14 +- test/mock/issuance_test.go | 190 +++++++++--------- test/mock/order_test.go | 40 ++-- 35 files changed, 340 insertions(+), 322 deletions(-) diff --git a/cmd/tribes-dcm/root/root.go b/cmd/tribes-dcm/root/root.go index b9a6a72..3352b43 100644 --- a/cmd/tribes-dcm/root/root.go +++ b/cmd/tribes-dcm/root/root.go @@ -43,10 +43,12 @@ func init() { Cmd.Flags().IntVar(&maxStartupTime, "max-startup-time", 10, "Maximum startup time in seconds") cobra.CheckErr(viper.BindPFlag(configs.MAX_STARTUP_TIME, Cmd.Flags().Lookup("max-startup-time"))) - // Database flags Cmd.Flags().StringVar(&databaseUrl, "database-url", "sqlite:///mnt/data/rollup.db", "SQLite database connection string") cobra.CheckErr(viper.BindPFlag(configs.DATABASE_URL, Cmd.Flags().Lookup("database-url"))) + Cmd.Flags().IntVar(&issuanceFee, "issuance-fee", 500, "Issuance fee in basis points (e.g., 500 = 5%, 250 = 2.5%, 1000 = 10%)") + cobra.CheckErr(viper.BindPFlag(configs.ISSUANCE_FEE, Cmd.Flags().Lookup("issuance-fee"))) + // Contracts flags Cmd.Flags().StringVar(&adminAddress, "admin-address", "", "Address of the admin user") cobra.CheckErr(viper.BindPFlag(configs.ADMIN_ADDRESS, Cmd.Flags().Lookup("admin-address"))) @@ -63,9 +65,6 @@ func init() { Cmd.Flags().StringVar(&safeErc1155MintAddress, "safe-erc1155-mint-address", "", "Address for safe ERC1155 minting") cobra.CheckErr(viper.BindPFlag(configs.SAFE_ERC1155_MINT_ADDRESS, Cmd.Flags().Lookup("safe-erc1155-mint-address"))) - Cmd.Flags().IntVar(&issuanceFee, "issuance-fee", 500, "Issuance fee in basis points (e.g., 500 = 5%, 250 = 2.5%, 1000 = 10%)") - cobra.CheckErr(viper.BindPFlag(configs.ISSUANCE_FEE, Cmd.Flags().Lookup("issuance-fee"))) - Cmd.PreRunE = func(cmd *cobra.Command, args []string) error { var err error cfg, err = configs.LoadRollupConfig() diff --git a/docs/configs.md b/docs/configs.md index f34fc7e..17322f7 100644 --- a/docs/configs.md +++ b/docs/configs.md @@ -4,7 +4,7 @@ DO NOT EDIT. --> -# rollup Rollup Configuration +# Rollup Configuration This file documents the configuration options. diff --git a/go.mod b/go.mod index fcf03f0..3ec396c 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/go-playground/validator/v10 v10.26.0 github.com/google/wire v0.6.0 github.com/holiman/uint256 v1.3.2 - github.com/rollmelette/rollmelette v0.0.0-20251226042236-fcdb709c5635 + github.com/rollmelette/rollmelette v0.1.2 github.com/spf13/cobra v1.9.1 github.com/spf13/viper v1.20.1 github.com/stretchr/testify v1.10.0 diff --git a/go.sum b/go.sum index f9574f8..ae91ac7 100644 --- a/go.sum +++ b/go.sum @@ -63,8 +63,8 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRI github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= -github.com/rollmelette/rollmelette v0.0.0-20251226042236-fcdb709c5635 h1:UpAdECibktivbj1ZNF+sanRCNFmdSdGacQAhC3oVzxk= -github.com/rollmelette/rollmelette v0.0.0-20251226042236-fcdb709c5635/go.mod h1:vi9BDrdDsL59Qb+AsuxHktniuXZ68esNc/UJlgW5fOI= +github.com/rollmelette/rollmelette v0.1.2 h1:flXAq1d0tBruXg2x6nAdeu7ZwvBpbUpt+dHawaEojrU= +github.com/rollmelette/rollmelette v0.1.2/go.mod h1:vi9BDrdDsL59Qb+AsuxHktniuXZ68esNc/UJlgW5fOI= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sagikazarmark/locafero v0.7.0 h1:5MqpDsTGNDhY8sGp0Aowyf0qKsPrhewaLSsFaodPcyo= github.com/sagikazarmark/locafero v0.7.0/go.mod h1:2za3Cg5rMaTMoG/2Ulr9AwtFaIppKXTRYnozin4aB5k= diff --git a/internal/domain/entity/issuance.go b/internal/domain/entity/issuance.go index f752a30..bea1393 100644 --- a/internal/domain/entity/issuance.go +++ b/internal/domain/entity/issuance.go @@ -4,7 +4,7 @@ import ( "errors" "fmt" - "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" + . "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" "github.com/holiman/uint256" ) @@ -28,11 +28,11 @@ type Issuance struct { Title string `json:"title,omitempty" gorm:"not null"` Description string `json:"description,omitempty" gorm:"not null"` Promotion string `json:"promotion,omitempty" gorm:"not null"` - Token types.Address `json:"token,omitempty" gorm:"types:text;not null"` - CreatorAddress types.Address `json:"creator_address,omitempty" gorm:"types:text;not null"` - CollateralAddress types.Address `json:"collateral_address,omitempty" gorm:"types:text;not null"` + Token Address `json:"token,omitempty" gorm:"types:text;not null"` + CreatorAddress Address `json:"creator_address,omitempty" gorm:"types:text;not null"` + CollateralAddress Address `json:"collateral_address,omitempty" gorm:"types:text;not null"` CollateralAmount *uint256.Int `json:"collateral_amount,omitempty" gorm:"types:text;not null"` - BadgeAddress types.Address `json:"badge_address,omitempty" gorm:"types:text;not null"` + BadgeAddress Address `json:"badge_address,omitempty" gorm:"types:text;not null"` DebtIssued *uint256.Int `json:"debt_issued,omitempty" gorm:"types:text;not null"` MaxInterestRate *uint256.Int `json:"max_interest_rate,omitempty" gorm:"types:text;not null"` TotalObligation *uint256.Int `json:"total_obligation,omitempty" gorm:"types:text;not null;default:0"` @@ -45,7 +45,7 @@ type Issuance struct { UpdatedAt int64 `json:"updated_at,omitempty" gorm:"default:0"` } -func NewIssuance(title string, description string, promotion string, token types.Address, creatorAddress types.Address, collateralAddress types.Address, collateralAmount *uint256.Int, badgeAddress types.Address, debtIssued *uint256.Int, maxInterestRate *uint256.Int, closesAt int64, maturityAt int64, createdAt int64) (*Issuance, error) { +func NewIssuance(title string, description string, promotion string, token Address, creatorAddress Address, collateralAddress Address, collateralAmount *uint256.Int, badgeAddress Address, debtIssued *uint256.Int, maxInterestRate *uint256.Int, closesAt int64, maturityAt int64, createdAt int64) (*Issuance, error) { issuance := &Issuance{ Title: title, Description: description, @@ -79,19 +79,19 @@ func (a *Issuance) validate() error { if a.Promotion == "" { return fmt.Errorf("%w: promotion cannot be empty", ErrInvalidIssuance) } - if a.Token == (types.Address{}) { + if a.Token == (Address{}) { return fmt.Errorf("%w: invalid token address", ErrInvalidIssuance) } - if a.CreatorAddress == (types.Address{}) { + if a.CreatorAddress == (Address{}) { return fmt.Errorf("%w: invalid creator address", ErrInvalidIssuance) } - if a.CollateralAddress == (types.Address{}) { + if a.CollateralAddress == (Address{}) { return fmt.Errorf("%w: invalid collateral address", ErrInvalidIssuance) } if a.CollateralAmount.Sign() == 0 { return fmt.Errorf("%w: collateral amount cannot be zero", ErrInvalidIssuance) } - if a.BadgeAddress == (types.Address{}) { + if a.BadgeAddress == (Address{}) { return fmt.Errorf("%w: invalid badge address", ErrInvalidIssuance) } if a.DebtIssued.Sign() == 0 { diff --git a/internal/domain/entity/order.go b/internal/domain/entity/order.go index 1092cf0..92b7733 100644 --- a/internal/domain/entity/order.go +++ b/internal/domain/entity/order.go @@ -4,7 +4,7 @@ import ( "errors" "fmt" - "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" + . "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" "github.com/holiman/uint256" ) @@ -26,23 +26,23 @@ const ( ) type Order struct { - Id uint `json:"id" gorm:"primaryKey"` - IssuanceId uint `json:"issuance_id" gorm:"not null;index"` - InvestorAddress types.Address `json:"investor_address,omitempty" gorm:"not null"` - Amount *uint256.Int `json:"amount,omitempty" gorm:"types:text;not null"` - InterestRate *uint256.Int `json:"interest_rate,omitempty" gorm:"types:text;not null"` - State OrderState `json:"state,omitempty" gorm:"types:text;not null"` - CreatedAt int64 `json:"created_at,omitempty" gorm:"not null"` - UpdatedAt int64 `json:"updated_at,omitempty" gorm:"default:0"` + Id uint `json:"id" gorm:"primaryKey"` + IssuanceId uint `json:"issuance_id" gorm:"not null;index"` + InvestorAddress Address `json:"investor_address,omitempty" gorm:"not null"` + Amount *uint256.Int `json:"amount,omitempty" gorm:"types:text;not null"` + InterestRate *uint256.Int `json:"interest_rate,omitempty" gorm:"types:text;not null"` + State OrderState `json:"state,omitempty" gorm:"types:text;not null"` + CreatedAt int64 `json:"created_at,omitempty" gorm:"not null"` + UpdatedAt int64 `json:"updated_at,omitempty" gorm:"default:0"` } -func NewOrder(issuanceId uint, investorAddress types.Address, amount *uint256.Int, interestRate *uint256.Int, createdAt int64) (*Order, error) { +func NewOrder(issuanceId uint, investorAddress Address, amount *uint256.Int, interestRate *uint256.Int, state OrderState, createdAt int64) (*Order, error) { order := &Order{ IssuanceId: issuanceId, InvestorAddress: investorAddress, Amount: amount, InterestRate: interestRate, - State: OrderStatePending, + State: state, CreatedAt: createdAt, } if err := order.validate(); err != nil { @@ -55,7 +55,7 @@ func (b *Order) validate() error { if b.IssuanceId == 0 { return fmt.Errorf("%w: Issuance ID cannot be zero", ErrInvalidOrder) } - if b.InvestorAddress == (types.Address{}) { + if b.InvestorAddress == (Address{}) { return fmt.Errorf("%w: investor address cannot be empty", ErrInvalidOrder) } if b.Amount.Sign() <= 0 { diff --git a/internal/domain/entity/user.go b/internal/domain/entity/user.go index ae9a83a..9281239 100644 --- a/internal/domain/entity/user.go +++ b/internal/domain/entity/user.go @@ -4,7 +4,7 @@ import ( "errors" "fmt" - "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" + . "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" ) var ( @@ -24,13 +24,13 @@ const ( type User struct { Id uint `json:"id" gorm:"primaryKey"` Role UserRole `json:"role,omitempty" gorm:"not null"` - Address types.Address `json:"address,omitempty" gorm:"types:text;uniqueIndex;not null"` + Address Address `json:"address,omitempty" gorm:"types:text;uniqueIndex;not null"` SocialAccounts []*SocialAccount `json:"social_accounts,omitempty" gorm:"foreignKey:UserId;constraint:OnDelete:CASCADE"` CreatedAt int64 `json:"created_at,omitempty" gorm:"not null"` UpdatedAt int64 `json:"updated_at,omitempty" gorm:"default:0"` } -func NewUser(role string, address types.Address, createdAt int64) (*User, error) { +func NewUser(role string, address Address, createdAt int64) (*User, error) { user := &User{ Role: UserRole(role), SocialAccounts: []*SocialAccount{}, @@ -50,7 +50,7 @@ func (u *User) validate() error { if u.Role != UserRoleAdmin && u.Role != UserRoleCreator && u.Role != UserRoleInvestor && u.Role != UserRoleVerifier { return fmt.Errorf("%w: invalid role", ErrInvalidUser) } - if u.Address == (types.Address{}) { + if u.Address == (Address{}) { return fmt.Errorf("%w: address cannot be empty", ErrInvalidUser) } if u.CreatedAt == 0 { diff --git a/internal/infra/repository/repository.go b/internal/infra/repository/repository.go index 9029803..efdce51 100644 --- a/internal/infra/repository/repository.go +++ b/internal/infra/repository/repository.go @@ -2,13 +2,14 @@ package repository import ( "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/domain/entity" - types "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" + . "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" ) type IssuanceRepository interface { CreateIssuance(issuance *entity.Issuance) (*entity.Issuance, error) - FindIssuancesByCreatorAddress(creator types.Address) ([]*entity.Issuance, error) - FindIssuancesByInvestorAddress(investor types.Address) ([]*entity.Issuance, error) + FindIssuancesByCreatorAddress(creator Address) ([]*entity.Issuance, error) + FindOngoingIssuanceByCreatorAddress(creator Address) (*entity.Issuance, error) + FindIssuancesByInvestorAddress(investor Address) ([]*entity.Issuance, error) FindIssuanceById(id uint) (*entity.Issuance, error) FindAllIssuances() ([]*entity.Issuance, error) UpdateIssuance(Issuance *entity.Issuance) (*entity.Issuance, error) @@ -19,7 +20,7 @@ type OrderRepository interface { FindOrderById(id uint) (*entity.Order, error) FindOrdersByIssuanceId(id uint) ([]*entity.Order, error) FindOrdersByState(issuanceId uint, state string) ([]*entity.Order, error) - FindOrdersByInvestorAddress(investor types.Address) ([]*entity.Order, error) + FindOrdersByInvestorAddress(investor Address) ([]*entity.Order, error) FindAllOrders() ([]*entity.Order, error) UpdateOrder(order *entity.Order) (*entity.Order, error) DeleteOrder(id uint) error @@ -35,9 +36,9 @@ type SocialAccountRepository interface { type UserRepository interface { CreateUser(user *entity.User) (*entity.User, error) FindUsersByRole(role string) ([]*entity.User, error) - FindUserByAddress(address types.Address) (*entity.User, error) + FindUserByAddress(address Address) (*entity.User, error) FindAllUsers() ([]*entity.User, error) - DeleteUser(address types.Address) error + DeleteUser(address Address) error } type Repository interface { diff --git a/internal/infra/repository/sqlite/issuance.go b/internal/infra/repository/sqlite/issuance.go index ceaa55f..41eabe4 100644 --- a/internal/infra/repository/sqlite/issuance.go +++ b/internal/infra/repository/sqlite/issuance.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/domain/entity" - "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" + . "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" "gorm.io/gorm" ) @@ -16,49 +16,63 @@ func (r *SQLiteRepository) CreateIssuance(input *entity.Issuance) (*entity.Issua } func (r *SQLiteRepository) FindIssuanceById(id uint) (*entity.Issuance, error) { - var Issuance entity.Issuance + var issuance entity.Issuance if err := r.Db. Preload("Orders"). - First(&Issuance, id).Error; err != nil { + First(&issuance, id).Error; err != nil { if err == gorm.ErrRecordNotFound { return nil, entity.ErrIssuanceNotFound } return nil, fmt.Errorf("failed to find issuance by id: %w", err) } - return &Issuance, nil + return &issuance, nil } func (r *SQLiteRepository) FindAllIssuances() ([]*entity.Issuance, error) { - var Issuances []*entity.Issuance + var issuance []*entity.Issuance if err := r.Db. Preload("Orders"). - Find(&Issuances).Error; err != nil { + Find(&issuance).Error; err != nil { return nil, fmt.Errorf("failed to find all issuances: %w", err) } - return Issuances, nil + return issuance, nil } -func (r *SQLiteRepository) FindIssuancesByInvestorAddress(investor types.Address) ([]*entity.Issuance, error) { - var Issuances []*entity.Issuance +func (r *SQLiteRepository) FindIssuancesByInvestorAddress(investor Address) ([]*entity.Issuance, error) { + var issuance []*entity.Issuance if err := r.Db. Joins("JOIN orders ON orders.issuance_id = issuances.id"). Where("orders.investor_address = ?", investor). Preload("Orders"). - Find(&Issuances).Error; err != nil { + Find(&issuance).Error; err != nil { return nil, fmt.Errorf("failed to find Issuances by investor: %w", err) } - return Issuances, nil + return issuance, nil } -func (r *SQLiteRepository) FindIssuancesByCreatorAddress(creator types.Address) ([]*entity.Issuance, error) { - var Issuances []*entity.Issuance +func (r *SQLiteRepository) FindIssuancesByCreatorAddress(creator Address) ([]*entity.Issuance, error) { + var issuance []*entity.Issuance if err := r.Db. Where("creator_address = ?", creator). Preload("Orders"). - Find(&Issuances).Error; err != nil { + Find(&issuance).Error; err != nil { return nil, fmt.Errorf("failed to find issuances by creator: %w", err) } - return Issuances, nil + return issuance, nil +} + +func (r *SQLiteRepository) FindOngoingIssuanceByCreatorAddress(creator Address) (*entity.Issuance, error) { + var issuance entity.Issuance + if err := r.Db. + Where("creator_address = ? AND state = ?", creator, entity.IssuanceStateOngoing). + Preload("Orders"). + First(&issuance).Error; err != nil { + if err == gorm.ErrRecordNotFound { + return nil, entity.ErrIssuanceNotFound + } + return nil, fmt.Errorf("failed to find ongoing issuance by creator: %w", err) + } + return &issuance, nil } func (r *SQLiteRepository) UpdateIssuance(input *entity.Issuance) (*entity.Issuance, error) { diff --git a/internal/infra/repository/sqlite/order.go b/internal/infra/repository/sqlite/order.go index d68b731..f2f1dff 100644 --- a/internal/infra/repository/sqlite/order.go +++ b/internal/infra/repository/sqlite/order.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/domain/entity" - "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" + . "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" "gorm.io/gorm" ) @@ -44,7 +44,7 @@ func (r *SQLiteRepository) FindOrdersByState(issuanceId uint, state string) ([]* return orders, nil } -func (r *SQLiteRepository) FindOrdersByInvestorAddress(investor types.Address) ([]*entity.Order, error) { +func (r *SQLiteRepository) FindOrdersByInvestorAddress(investor Address) ([]*entity.Order, error) { var orders []*entity.Order if err := r.Db.Where("investor_address = ?", investor).Find(&orders).Error; err != nil { return nil, fmt.Errorf("failed to find orders by investor: %w", err) diff --git a/internal/infra/repository/sqlite/sqlite.go b/internal/infra/repository/sqlite/sqlite.go index 32e08e6..af1e54b 100644 --- a/internal/infra/repository/sqlite/sqlite.go +++ b/internal/infra/repository/sqlite/sqlite.go @@ -14,7 +14,7 @@ import ( "github.com/2025-2A-T20-G91-INTERNO/src/rollup/configs" "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/domain/entity" - types "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" + . "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" ) type SQLiteRepository struct { @@ -73,7 +73,7 @@ func NewSQLiteRepository(ctx context.Context, conn string) (*SQLiteRepository, e configs.SetDefaults() - var adminAddr, verifierAddr types.Address + var adminAddr, verifierAddr Address if isMemory { a, err := configs.GetAdminAddressTest() @@ -82,7 +82,7 @@ func NewSQLiteRepository(ctx context.Context, conn string) (*SQLiteRepository, e } else if err == configs.ErrNotDefined { return nil, fmt.Errorf("rollup_ADMIN_ADDRESS_TEST is required for the rollup service: %w", err) } - adminAddr = types.HexToAddress(a.Hex()) + adminAddr = HexToAddress(a.Hex()) v, err := configs.GetVerifierAddressTest() if err != nil && err != configs.ErrNotDefined { @@ -90,7 +90,7 @@ func NewSQLiteRepository(ctx context.Context, conn string) (*SQLiteRepository, e } else if err == configs.ErrNotDefined { return nil, fmt.Errorf("rollup_VERIFIER_ADDRESS_TEST is required for the rollup service: %w", err) } - verifierAddr = types.HexToAddress(v.Hex()) + verifierAddr = HexToAddress(v.Hex()) } else { a, err := configs.GetAdminAddress() if err != nil && err != configs.ErrNotDefined { @@ -98,7 +98,7 @@ func NewSQLiteRepository(ctx context.Context, conn string) (*SQLiteRepository, e } else if err == configs.ErrNotDefined { return nil, fmt.Errorf("rollup_ADMIN_ADDRESS is required for the rollup service: %w", err) } - adminAddr = types.HexToAddress(a.Hex()) + adminAddr = HexToAddress(a.Hex()) v, err := configs.GetVerifierAddress() if err != nil && err != configs.ErrNotDefined { @@ -106,7 +106,7 @@ func NewSQLiteRepository(ctx context.Context, conn string) (*SQLiteRepository, e } else if err == configs.ErrNotDefined { return nil, fmt.Errorf("rollup_VERIFIER_ADDRESS is required for the rollup service: %w", err) } - verifierAddr = types.HexToAddress(v.Hex()) + verifierAddr = HexToAddress(v.Hex()) } baseTime := time.Now().Unix() diff --git a/internal/infra/repository/sqlite/user.go b/internal/infra/repository/sqlite/user.go index 7292eba..3e0454a 100644 --- a/internal/infra/repository/sqlite/user.go +++ b/internal/infra/repository/sqlite/user.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/domain/entity" - "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" + . "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" "gorm.io/gorm" ) @@ -15,7 +15,7 @@ func (r *SQLiteRepository) CreateUser(input *entity.User) (*entity.User, error) return input, nil } -func (r *SQLiteRepository) FindUserByAddress(address types.Address) (*entity.User, error) { +func (r *SQLiteRepository) FindUserByAddress(address Address) (*entity.User, error) { var user entity.User if err := r.Db.Preload("SocialAccounts").Where("address = ?", address).First(&user).Error; err != nil { if err == gorm.ErrRecordNotFound { @@ -42,7 +42,7 @@ func (r *SQLiteRepository) FindAllUsers() ([]*entity.User, error) { return users, nil } -func (r *SQLiteRepository) DeleteUser(address types.Address) error { +func (r *SQLiteRepository) DeleteUser(address Address) error { res := r.Db.Where("address = ?", address).Delete(&entity.User{}) if res.Error != nil { return fmt.Errorf("failed to delete user: %w", res.Error) diff --git a/internal/infra/rollup/handler/advance/issuance.go b/internal/infra/rollup/handler/advance/issuance.go index 9d0fb1e..127c50f 100644 --- a/internal/infra/rollup/handler/advance/issuance.go +++ b/internal/infra/rollup/handler/advance/issuance.go @@ -19,6 +19,13 @@ import ( "github.com/rollmelette/rollmelette" ) +// BasisPointsDivisor is the divisor used for basis point calculations. +// 10000 basis points = 100%, so 1 basis point = 0.01%. +// Example: 900 basis points = 9%, 950 basis points = 9.5% +var ( + BasisPointsDivisor = uint256.NewInt(10000) +) + type IssuanceAdvanceHandlers struct { Config *configs.RollupConfig OrderRepository repository.OrderRepository @@ -262,9 +269,9 @@ func (h *IssuanceAdvanceHandlers) SettleIssuance(env rollmelette.Env, metadata r // Process settled orders for _, order := range res.Orders { if order.State == string(entity.OrderStateSettled) { - // Calculate interest for this order + // Calculate interest for this order using basis points interest := new(uint256.Int).Mul(order.Amount, order.InterestRate) - interest.Div(interest, uint256.NewInt(100)) + interest.Div(interest, BasisPointsDivisor) // Calculate total payment totalPayment := new(uint256.Int).Add(order.Amount, interest) @@ -293,7 +300,7 @@ func (h *IssuanceAdvanceHandlers) SettleIssuance(env rollmelette.Env, metadata r env.DelegateCallVoucher(common.Address(h.Config.SafeErc1155MintAddress), safeMintPayload) } } - + issuance, err := json.Marshal(res) if err != nil { return fmt.Errorf("failed to marshal response: %w", err) @@ -324,8 +331,9 @@ func (h *IssuanceAdvanceHandlers) ExecuteIssuanceCollateral(env rollmelette.Env, orderFinalValues := make(map[uint]*uint256.Int) for _, order := range res.Orders { if order.State == string(entity.OrderStateSettledByCollateral) { + // Calculate interest using basis points interest := new(uint256.Int).Mul(order.Amount, order.InterestRate) - interest.Div(interest, uint256.NewInt(100)) + interest.Div(interest, BasisPointsDivisor) finalValue := new(uint256.Int).Add(order.Amount, interest) orderFinalValues[order.Id] = finalValue totalFinalValue.Add(totalFinalValue, finalValue) diff --git a/internal/infra/rollup/handler/advance/user.go b/internal/infra/rollup/handler/advance/user.go index 9cedf0a..132ddf1 100644 --- a/internal/infra/rollup/handler/advance/user.go +++ b/internal/infra/rollup/handler/advance/user.go @@ -8,7 +8,7 @@ import ( "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/domain/entity" "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/infra/repository" "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/usecase/user" - types "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" + . "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" "github.com/ethereum/go-ethereum/common" "github.com/go-playground/validator/v10" "github.com/rollmelette/rollmelette" @@ -93,7 +93,7 @@ func (h *UserAdvanceHandlers) ERC20Withdraw(env rollmelette.Env, metadata rollme findUserByAddress := user.NewFindUserByAddressUseCase(h.UserRepository) res, err := findUserByAddress.Execute(&user.FindUserByAddressInputDTO{ - Address: types.Address(metadata.MsgSender), + Address: Address(metadata.MsgSender), }) if err != nil { return fmt.Errorf("failed to find user: %w", err) diff --git a/internal/infra/rollup/middleware/rbac.go b/internal/infra/rollup/middleware/rbac.go index f034fd3..e1e0986 100644 --- a/internal/infra/rollup/middleware/rbac.go +++ b/internal/infra/rollup/middleware/rbac.go @@ -6,7 +6,7 @@ import ( "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/infra/repository" "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/usecase/user" "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/router" - types "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" + . "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" "github.com/ethereum/go-ethereum/common" "github.com/rollmelette/rollmelette" ) @@ -28,14 +28,14 @@ func (f *RBACFactory) Create(roles []string) router.Middleware { switch h := handler.(type) { case router.AdvanceHandlerFunc: return router.AdvanceHandlerFunc(func(env rollmelette.Env, metadata rollmelette.Metadata, deposit rollmelette.Deposit, payload []byte) error { - var address types.Address + var address Address // Get the sender address from either ERC20 deposit or metadata erc20Deposit, ok := deposit.(*rollmelette.ERC20Deposit) if ok { - address = types.Address(erc20Deposit.Sender) + address = Address(erc20Deposit.Sender) } else { - address = types.Address(metadata.MsgSender) + address = Address(metadata.MsgSender) } // Find user and check roles diff --git a/internal/usecase/issuance/close_issuance.go b/internal/usecase/issuance/close_issuance.go index e121df9..7e28831 100644 --- a/internal/usecase/issuance/close_issuance.go +++ b/internal/usecase/issuance/close_issuance.go @@ -8,13 +8,20 @@ import ( "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/infra/repository" "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/usecase/order" "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/usecase/user" - "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" + . "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" "github.com/holiman/uint256" "github.com/rollmelette/rollmelette" ) +// BasisPointsDivisor is the divisor used for basis point calculations. +// 10000 basis points = 100%, so 1 basis point = 0.01%. +// Example: 900 basis points = 9%, 950 basis points = 9.5% +var ( + BasisPointsDivisor = uint256.NewInt(10000) +) + type CloseIssuanceInputDTO struct { - CreatorAddress types.Address `json:"creator_address" validate:"required"` + CreatorAddress Address `json:"creator_address" validate:"required"` } type CloseIssuanceOutputDTO struct { @@ -22,11 +29,11 @@ type CloseIssuanceOutputDTO struct { Title string `json:"title,omitempty"` Description string `json:"description,omitempty"` Promotion string `json:"promotion,omitempty"` - Token types.Address `json:"token,omitempty"` + Token Address `json:"token,omitempty"` Creator *user.UserOutputDTO `json:"creator,omitempty"` - CollateralAddress types.Address `json:"collateral,omitempty"` + CollateralAddress Address `json:"collateral,omitempty"` CollateralAmount *uint256.Int `json:"collateral_amount,omitempty"` - BadgeAddress types.Address `json:"badge_address,omitempty"` + BadgeAddress Address `json:"badge_address,omitempty"` DebtIssued *uint256.Int `json:"debt_issued,omitempty"` MaxInterestRate *uint256.Int `json:"max_interest_rate,omitempty"` TotalObligation *uint256.Int `json:"total_obligation,omitempty"` @@ -57,19 +64,9 @@ func (u *CloseIssuanceUseCase) Execute(input *CloseIssuanceInputDTO, metadata ro // ------------------------------------------------------------------------- // 1. Find ongoing issuance for the creator // ------------------------------------------------------------------------- - issuances, err := u.IssuanceRepository.FindIssuancesByCreatorAddress(input.CreatorAddress) + ongoingIssuance, err := u.IssuanceRepository.FindOngoingIssuanceByCreatorAddress(input.CreatorAddress) if err != nil { - return nil, err - } - var ongoingIssuance *entity.Issuance - for _, issuance := range issuances { - if issuance.State == entity.IssuanceStateOngoing { - ongoingIssuance = issuance - break - } - } - if ongoingIssuance == nil { - return nil, fmt.Errorf("no ongoing issuance found, cannot close it") + return nil, fmt.Errorf("no ongoing issuance found, cannot close it: %w", err) } // ------------------------------------------------------------------------- @@ -117,8 +114,9 @@ func (u *CloseIssuanceUseCase) Execute(input *CloseIssuanceInputDTO, metadata ro if debtRemaining.Lt(order.Amount) { acceptAmount = new(uint256.Int).Set(debtRemaining) } + // Calculate interest using basis points interest := new(uint256.Int).Mul(acceptAmount, order.InterestRate) - interest.Div(interest, uint256.NewInt(100)) + interest.Div(interest, BasisPointsDivisor) orderObligation := new(uint256.Int).Add(acceptAmount, interest) totalCollected.Add(totalCollected, acceptAmount) @@ -131,15 +129,19 @@ func (u *CloseIssuanceUseCase) Execute(input *CloseIssuanceInputDTO, metadata ro order.State = entity.OrderStatePartiallyAccepted // Create rejected order for the surplus rejectedAmount := new(uint256.Int).Sub(order.Amount, acceptAmount) - _, err := u.OrderRepository.CreateOrder(&entity.Order{ - IssuanceId: order.IssuanceId, - InvestorAddress: order.InvestorAddress, - Amount: rejectedAmount, - InterestRate: order.InterestRate, - State: entity.OrderStateRejected, - CreatedAt: order.CreatedAt, - UpdatedAt: metadata.BlockTimestamp, - }) + rejectedOrder, err := entity.NewOrder( + order.IssuanceId, + order.InvestorAddress, + rejectedAmount, + order.InterestRate, + entity.OrderStateRejected, + order.CreatedAt, + ) + if err != nil { + return nil, err + } + rejectedOrder.UpdatedAt = metadata.BlockTimestamp + _, err = u.OrderRepository.CreateOrder(rejectedOrder) if err != nil { return nil, err } diff --git a/internal/usecase/issuance/create_issuance.go b/internal/usecase/issuance/create_issuance.go index e7927f9..3663c4b 100644 --- a/internal/usecase/issuance/create_issuance.go +++ b/internal/usecase/issuance/create_issuance.go @@ -8,7 +8,7 @@ import ( "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/domain/entity" "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/infra/repository" "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/usecase/user" - "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" + . "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" @@ -17,14 +17,14 @@ import ( ) type CreateIssuanceInputDTO struct { - Title string `json:"title" validate:"required,min=3,max=100"` - Description string `json:"description" validate:"required,min=10,max=1000"` - Promotion string `json:"promotion" validate:"required,min=5,max=500"` - Token types.Address `json:"token" validate:"required"` - DebtIssued *uint256.Int `json:"debt_issued" validate:"required"` - MaxInterestRate *uint256.Int `json:"max_interest_rate" validate:"required"` - ClosesAt int64 `json:"closes_at" validate:"required"` - MaturityAt int64 `json:"maturity_at" validate:"required"` + Title string `json:"title" validate:"required,min=3,max=100"` + Description string `json:"description" validate:"required,min=10,max=1000"` + Promotion string `json:"promotion" validate:"required,min=5,max=500"` + Token Address `json:"token" validate:"required"` + DebtIssued *uint256.Int `json:"debt_issued" validate:"required"` + MaxInterestRate *uint256.Int `json:"max_interest_rate" validate:"required"` + ClosesAt int64 `json:"closes_at" validate:"required"` + MaturityAt int64 `json:"maturity_at" validate:"required"` } type CreateIssuanceOutputDTO struct { @@ -32,11 +32,11 @@ type CreateIssuanceOutputDTO struct { Title string `json:"title,omitempty"` Description string `json:"description,omitempty"` Promotion string `json:"promotion,omitempty"` - Token types.Address `json:"token,omitempty"` + Token Address `json:"token,omitempty"` Creator *user.UserOutputDTO `json:"creator,omitempty"` - CollateralAddress types.Address `json:"collateral,omitempty"` + CollateralAddress Address `json:"collateral,omitempty"` CollateralAmount *uint256.Int `json:"collateral_amount,omitempty"` - BadgeAddress types.Address `json:"badge_address,omitempty"` + BadgeAddress Address `json:"badge_address,omitempty"` DebtIssued *uint256.Int `json:"debt_issued"` MaxInterestRate *uint256.Int `json:"max_interest_rate"` State string `json:"state"` @@ -70,7 +70,7 @@ func (c *CreateIssuanceUseCase) Execute(input *CreateIssuanceInputDTO, deposit r return nil, fmt.Errorf("invalid deposit types: %T", deposit) } - creator, err := c.UserRepository.FindUserByAddress(types.Address(erc20Deposit.Sender)) + creator, err := c.UserRepository.FindUserByAddress(Address(erc20Deposit.Sender)) if err != nil { return nil, fmt.Errorf("error finding user: %w", err) } @@ -84,13 +84,13 @@ func (c *CreateIssuanceUseCase) Execute(input *CreateIssuanceInputDTO, deposit r return nil, fmt.Errorf("error getting badge bytecode: %w", err) } - issuances, err := c.IssuanceRepository.FindIssuancesByCreatorAddress(types.Address(erc20Deposit.Sender)) + issuances, err := c.IssuanceRepository.FindIssuancesByCreatorAddress(Address(erc20Deposit.Sender)) if err != nil { - return nil, fmt.Errorf("error retrieving Issuances: %w", err) + return nil, fmt.Errorf("error retrieving issuances: %w", err) } for _, issuance := range issuances { - if issuance.State != entity.IssuanceStateSettled && issuance.State != entity.IssuanceStateCollateralExecuted { - return nil, fmt.Errorf("active issuance exists, cannot create a new issuance") + if issuance.State == entity.IssuanceStateOngoing || issuance.State == entity.IssuanceStateClosed { + return nil, fmt.Errorf("cannot create a new issuance: creator has an active issuance (id: %d, state: %s)", issuance.Id, issuance.State) } } @@ -113,10 +113,10 @@ func (c *CreateIssuanceUseCase) Execute(input *CreateIssuanceInputDTO, deposit r input.Description, input.Promotion, input.Token, - types.Address(erc20Deposit.Sender), - types.Address(erc20Deposit.Token), + Address(erc20Deposit.Sender), + Address(erc20Deposit.Token), uint256.MustFromBig(erc20Deposit.Value), - types.Address(badgeAddress), + Address(badgeAddress), input.DebtIssued, input.MaxInterestRate, input.ClosesAt, diff --git a/internal/usecase/issuance/execute_issuance_collateral.go b/internal/usecase/issuance/execute_issuance_collateral.go index 6739e81..7f87278 100644 --- a/internal/usecase/issuance/execute_issuance_collateral.go +++ b/internal/usecase/issuance/execute_issuance_collateral.go @@ -7,7 +7,7 @@ import ( "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/infra/repository" "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/usecase/order" "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/usecase/user" - "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" + . "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" "github.com/holiman/uint256" "github.com/rollmelette/rollmelette" ) @@ -21,11 +21,11 @@ type ExecuteIssuanceCollateralOutputDTO struct { Title string `json:"title,omitempty"` Description string `json:"description,omitempty"` Promotion string `json:"promotion,omitempty"` - Token types.Address `json:"token"` + Token Address `json:"token"` Creator *user.UserOutputDTO `json:"creator"` - CollateralAddress types.Address `json:"collateral"` + CollateralAddress Address `json:"collateral"` CollateralAmount *uint256.Int `json:"collateral_amount"` - BadgeAddress types.Address `json:"badge_address"` + BadgeAddress Address `json:"badge_address"` DebtIssued *uint256.Int `json:"debt_issued"` MaxInterestRate *uint256.Int `json:"max_interest_rate"` TotalObligation *uint256.Int `json:"total_obligation"` @@ -62,17 +62,13 @@ func (uc *ExecuteIssuanceCollateralUseCase) Execute(input *ExecuteIssuanceCollat return nil, err } - var ordersToUpdate []*entity.Order for _, order := range issuance.Orders { if order.State == entity.OrderStateAccepted || order.State == entity.OrderStatePartiallyAccepted { order.State = entity.OrderStateSettledByCollateral order.UpdatedAt = metadata.BlockTimestamp - ordersToUpdate = append(ordersToUpdate, order) - } - } - for _, order := range ordersToUpdate { - if _, err := uc.OrderRepository.UpdateOrder(order); err != nil { - return nil, fmt.Errorf("error updating order: %w", err) + if _, err := uc.OrderRepository.UpdateOrder(order); err != nil { + return nil, fmt.Errorf("error updating order: %w", err) + } } } diff --git a/internal/usecase/issuance/find_issuance_by_creator_address.go b/internal/usecase/issuance/find_issuance_by_creator_address.go index 14f31ca..4ceb5bb 100644 --- a/internal/usecase/issuance/find_issuance_by_creator_address.go +++ b/internal/usecase/issuance/find_issuance_by_creator_address.go @@ -6,11 +6,11 @@ import ( "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/infra/repository" "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/usecase/order" "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/usecase/user" - "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" + . "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" ) type FindIssuancesByCreatorAddressInputDTO struct { - CreatorAddress types.Address `json:"creator" validate:"required"` + CreatorAddress Address `json:"creator" validate:"required"` } type FindIssuancesByCreatorAddressOutputDTO []*IssuanceOutputDTO diff --git a/internal/usecase/issuance/find_issuance_by_investor_address.go b/internal/usecase/issuance/find_issuance_by_investor_address.go index 4d4ebe4..12d76ed 100644 --- a/internal/usecase/issuance/find_issuance_by_investor_address.go +++ b/internal/usecase/issuance/find_issuance_by_investor_address.go @@ -6,11 +6,11 @@ import ( "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/infra/repository" "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/usecase/order" "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/usecase/user" - "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" + . "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" ) type FindIssuancesByInvestorAddressInputDTO struct { - InvestorAddress types.Address `json:"investor_address" validate:"required"` + InvestorAddress Address `json:"investor_address" validate:"required"` } type FindIssuancesByInvestorAddressOutputDTO []*IssuanceOutputDTO diff --git a/internal/usecase/issuance/general_dto.go b/internal/usecase/issuance/general_dto.go index f18bb72..68445ff 100644 --- a/internal/usecase/issuance/general_dto.go +++ b/internal/usecase/issuance/general_dto.go @@ -3,7 +3,7 @@ package issuance import ( "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/usecase/order" "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/usecase/user" - "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" + . "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" "github.com/holiman/uint256" ) @@ -12,11 +12,11 @@ type IssuanceOutputDTO struct { Title string `json:"title,omitempty"` Description string `json:"description,omitempty"` Promotion string `json:"promotion,omitempty"` - Token types.Address `json:"token"` + Token Address `json:"token"` Creator *user.UserOutputDTO `json:"creator"` - CollateralAddress types.Address `json:"collateral"` + CollateralAddress Address `json:"collateral"` CollateralAmount *uint256.Int `json:"collateral_amount"` - BadgeAddress types.Address `json:"badge_address"` + BadgeAddress Address `json:"badge_address"` DebtIssued *uint256.Int `json:"debt_issued"` MaxInterestRate *uint256.Int `json:"max_interest_rate"` TotalObligation *uint256.Int `json:"total_obligation"` diff --git a/internal/usecase/issuance/settle_issuance.go b/internal/usecase/issuance/settle_issuance.go index 26f41ef..4e2ee84 100644 --- a/internal/usecase/issuance/settle_issuance.go +++ b/internal/usecase/issuance/settle_issuance.go @@ -7,7 +7,7 @@ import ( "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/infra/repository" "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/usecase/order" "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/usecase/user" - "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" + . "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" "github.com/holiman/uint256" "github.com/rollmelette/rollmelette" ) @@ -21,11 +21,11 @@ type SettleIssuanceOutputDTO struct { Title string `json:"title,omitempty"` Description string `json:"description,omitempty"` Promotion string `json:"promotion,omitempty"` - Token types.Address `json:"token"` + Token Address `json:"token"` Creator *user.UserOutputDTO `json:"creator"` - CollateralAddress types.Address `json:"collateral"` + CollateralAddress Address `json:"collateral"` CollateralAmount *uint256.Int `json:"collateral_amount"` - BadgeAddress types.Address `json:"badge_address"` + BadgeAddress Address `json:"badge_address"` DebtIssued *uint256.Int `json:"debt_issued"` MaxInterestRate *uint256.Int `json:"max_interest_rate"` TotalObligation *uint256.Int `json:"total_obligation"` @@ -75,22 +75,19 @@ func (uc *SettleIssuanceUseCase) Execute( return nil, err } - var ordersToUpdate []*entity.Order for _, order := range issuance.Orders { if order.State == entity.OrderStateAccepted || order.State == entity.OrderStatePartiallyAccepted { order.State = entity.OrderStateSettled order.UpdatedAt = metadata.BlockTimestamp - ordersToUpdate = append(ordersToUpdate, order) - } - } - for _, order := range ordersToUpdate { - if _, err := uc.OrderRepository.UpdateOrder(order); err != nil { - return nil, fmt.Errorf("error updating order: %w", err) + if _, err := uc.OrderRepository.UpdateOrder(order); err != nil { + return nil, fmt.Errorf("error updating order: %w", err) + } } } issuance.State = entity.IssuanceStateSettled issuance.UpdatedAt = metadata.BlockTimestamp + res, err := uc.IssuanceRepository.UpdateIssuance(issuance) if err != nil { return nil, fmt.Errorf("error updating issuance: %w", err) @@ -177,7 +174,7 @@ func (uc *SettleIssuanceUseCase) Validate( return fmt.Errorf("deposit amount is lower than the total obligation") } - if Issuance.CreatorAddress != types.Address(deposit.Sender) { + if Issuance.CreatorAddress != Address(deposit.Sender) { return fmt.Errorf("only the issuance creator can settle the issuance") } return nil diff --git a/internal/usecase/order/cancel_order.go b/internal/usecase/order/cancel_order.go index d493084..efcb06d 100644 --- a/internal/usecase/order/cancel_order.go +++ b/internal/usecase/order/cancel_order.go @@ -6,7 +6,7 @@ import ( "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/domain/entity" "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/infra/repository" "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/usecase/user" - "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" + . "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" "github.com/holiman/uint256" "github.com/rollmelette/rollmelette" ) @@ -18,7 +18,7 @@ type CancelOrderInputDTO struct { type CancelOrderOutputDTO struct { Id uint `json:"id"` IssuanceId uint `json:"issuance_id"` - Token types.Address `json:"token"` + Token Address `json:"token"` Investor *user.UserOutputDTO `json:"investor"` Amount *uint256.Int `json:"amount"` InterestRate *uint256.Int `json:"interest_rate"` @@ -46,7 +46,7 @@ func (c *CancelOrderUseCase) Execute(input *CancelOrderInputDTO, metadata rollme if err != nil { return nil, err } - if order.InvestorAddress != types.Address(metadata.MsgSender) { + if order.InvestorAddress != Address(metadata.MsgSender) { return nil, errors.New("only the investor can cancel the order") } issuance, err := c.IssuanceRepository.FindIssuanceById(order.IssuanceId) diff --git a/internal/usecase/order/create_order.go b/internal/usecase/order/create_order.go index f612d7c..182697c 100644 --- a/internal/usecase/order/create_order.go +++ b/internal/usecase/order/create_order.go @@ -6,7 +6,7 @@ import ( "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/domain/entity" "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/infra/repository" "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/usecase/user" - "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" + . "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" "github.com/holiman/uint256" "github.com/rollmelette/rollmelette" ) @@ -59,7 +59,7 @@ func (c *CreateOrderUseCase) Execute(input *CreateOrderInputDTO, deposit rollmel return nil, fmt.Errorf("issuance issuance closed, order cannot be placed") } - if types.Address(erc20Deposit.Token) != issuance.Token { + if Address(erc20Deposit.Token) != issuance.Token { return nil, fmt.Errorf("invalid contract address provided for order creation: %v", erc20Deposit.Token) } @@ -69,9 +69,10 @@ func (c *CreateOrderUseCase) Execute(input *CreateOrderInputDTO, deposit rollmel order, err := entity.NewOrder( issuance.Id, - types.Address(erc20Deposit.Sender), + Address(erc20Deposit.Sender), uint256.MustFromBig(erc20Deposit.Value), input.InterestRate, + entity.OrderStatePending, metadata.BlockTimestamp, ) if err != nil { diff --git a/internal/usecase/order/find_orders_by_investor_address.go b/internal/usecase/order/find_orders_by_investor_address.go index 1ed45f6..b677c24 100644 --- a/internal/usecase/order/find_orders_by_investor_address.go +++ b/internal/usecase/order/find_orders_by_investor_address.go @@ -3,11 +3,11 @@ package order import ( "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/infra/repository" "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/usecase/user" - "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" + . "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" ) type FindOrdersByInvestorAddressInputDTO struct { - InvestorAddress types.Address `json:"investor_address" validate:"required"` + InvestorAddress Address `json:"investor_address" validate:"required"` } type FindOrdersByInvestorAddressOutputDTO []*OrderOutputDTO diff --git a/internal/usecase/social_account/create_social_account.go b/internal/usecase/social_account/create_social_account.go index f31a148..4fa098f 100644 --- a/internal/usecase/social_account/create_social_account.go +++ b/internal/usecase/social_account/create_social_account.go @@ -3,14 +3,14 @@ package social_account import ( "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/domain/entity" "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/infra/repository" - types "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" + . "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" "github.com/rollmelette/rollmelette" ) type CreateSocialAccountInputDTO struct { - Address types.Address `json:"address" validate:"required"` - Username string `json:"username" validate:"required"` - Platform string `json:"platform" validate:"required"` + Address Address `json:"address" validate:"required"` + Username string `json:"username" validate:"required"` + Platform string `json:"platform" validate:"required"` } type CreateSocialAccountOutputDTO struct { diff --git a/internal/usecase/user/create_user.go b/internal/usecase/user/create_user.go index a1fd3ed..50729ba 100644 --- a/internal/usecase/user/create_user.go +++ b/internal/usecase/user/create_user.go @@ -3,20 +3,20 @@ package user import ( "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/domain/entity" "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/infra/repository" - "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" + . "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" "github.com/holiman/uint256" "github.com/rollmelette/rollmelette" ) type CreateUserInputDTO struct { - Role string `json:"role" validate:"required"` - Address types.Address `json:"address" validate:"required"` + Role string `json:"role" validate:"required"` + Address Address `json:"address" validate:"required"` } type CreateUserOutputDTO struct { Id uint `json:"id"` Role string `json:"role"` - Address types.Address `json:"address"` + Address Address `json:"address"` SocialAccounts []*entity.SocialAccount `json:"social_accounts"` InvestmentLimit *uint256.Int `json:"investment_limit,omitempty" gorm:"type:bigint"` CreatedAt int64 `json:"created_at"` diff --git a/internal/usecase/user/delete_user_by_address.go b/internal/usecase/user/delete_user_by_address.go index bbfdb47..a628a3a 100644 --- a/internal/usecase/user/delete_user_by_address.go +++ b/internal/usecase/user/delete_user_by_address.go @@ -2,11 +2,11 @@ package user import ( "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/infra/repository" - "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" + . "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" ) type DeleteUserInputDTO struct { - Address types.Address `json:"address" validate:"required"` + Address Address `json:"address" validate:"required"` } type DeleteUserUseCase struct { diff --git a/internal/usecase/user/find_user_by_address.go b/internal/usecase/user/find_user_by_address.go index 4ca55e8..7dbc97c 100644 --- a/internal/usecase/user/find_user_by_address.go +++ b/internal/usecase/user/find_user_by_address.go @@ -2,11 +2,11 @@ package user import ( "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/infra/repository" - "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" + . "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" ) type FindUserByAddressInputDTO struct { - Address types.Address `json:"address" validate:"required"` + Address Address `json:"address" validate:"required"` } type FindUserByAddressUseCase struct { diff --git a/internal/usecase/user/general_dto.go b/internal/usecase/user/general_dto.go index 1ecff79..77c73ba 100644 --- a/internal/usecase/user/general_dto.go +++ b/internal/usecase/user/general_dto.go @@ -2,18 +2,18 @@ package user import ( "github.com/2025-2A-T20-G91-INTERNO/src/rollup/internal/domain/entity" - "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" + . "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" ) type BalanceOfInputDTO struct { - Token types.Address `json:"token"` - Address types.Address `json:"address" validate:"required"` + Token Address `json:"token"` + Address Address `json:"address" validate:"required"` } type UserOutputDTO struct { Id uint `json:"id"` Role string `json:"role"` - Address types.Address `json:"address"` + Address Address `json:"address"` SocialAccounts []*entity.SocialAccount `json:"social_accounts"` CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` diff --git a/internal/usecase/user/withdraw.go b/internal/usecase/user/withdraw.go index d296e9a..cc33c28 100644 --- a/internal/usecase/user/withdraw.go +++ b/internal/usecase/user/withdraw.go @@ -1,20 +1,20 @@ package user import ( - "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" + . "github.com/2025-2A-T20-G91-INTERNO/src/rollup/pkg/types" "github.com/holiman/uint256" ) type WithdrawInputDTO struct { - Token types.Address `json:"token" validate:"required"` - Amount *uint256.Int `json:"amount" validate:"required"` + Token Address `json:"token" validate:"required"` + Amount *uint256.Int `json:"amount" validate:"required"` } type EmergencyERC20WithdrawInputDTO struct { - To types.Address `json:"to" validate:"required"` - Token types.Address `json:"token" validate:"required"` + To Address `json:"to" validate:"required"` + Token Address `json:"token" validate:"required"` } type EmergencyEtherWithdrawInputDTO struct { - To types.Address `json:"to" validate:"required"` + To Address `json:"to" validate:"required"` } diff --git a/test/integration/issuance.test.ts b/test/integration/issuance.test.ts index c4de9d3..fe4d811 100644 --- a/test/integration/issuance.test.ts +++ b/test/integration/issuance.test.ts @@ -76,7 +76,7 @@ describe("Issuance Tests", () => { description: "testtesttesttesttest", promotion: "testtesttesttesttest", token: TOKEN_ADDRESS, - max_interest_rate: "10", + max_interest_rate: "1000", debt_issued: "100000", closes_at: closesAt, maturity_at: maturityAt, @@ -127,7 +127,7 @@ describe("Issuance Tests", () => { // Verify notice for issuance creation const expectedCreateIssuanceNoticeOutput = encodeNoticeOutput({ payload: stringToHex( - `issuance created - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"${TOKEN_ADDRESS.toLowerCase()}","creator":{"id":3,"role":"creator","address":"${CREATOR_ADDRESS}","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":${baseTime}}],"created_at":${baseTime},"updated_at":0},"collateral":"${COLLATERAL.toLowerCase()}","collateral_amount":"10000","badge_address":"${badgeAddress}","debt_issued":"100000","max_interest_rate":"10","state":"ongoing","orders":[],"created_at":${baseTime},"closes_at":${closesAt},"maturity_at":${maturityAt}}`, + `issuance created - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"${TOKEN_ADDRESS.toLowerCase()}","creator":{"id":3,"role":"creator","address":"${CREATOR_ADDRESS}","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":${baseTime}}],"created_at":${baseTime},"updated_at":0},"collateral":"${COLLATERAL.toLowerCase()}","collateral_amount":"10000","badge_address":"${badgeAddress}","debt_issued":"100000","max_interest_rate":"1000","state":"ongoing","orders":[],"created_at":${baseTime},"closes_at":${closesAt},"maturity_at":${maturityAt}}`, ), }); expect(bytesToHex(outputs[1])).toBe(expectedCreateIssuanceNoticeOutput); @@ -180,7 +180,7 @@ describe("Issuance Tests", () => { collateral: COLLATERAL.toLowerCase(), collateral_amount: "10000", badge_address: badgeAddress, - max_interest_rate: "10", + max_interest_rate: "1000", debt_issued: "100000", total_obligation: "0", total_raised: "0", @@ -243,7 +243,7 @@ describe("Issuance Tests", () => { collateral: COLLATERAL.toLowerCase(), collateral_amount: "10000", badge_address: badgeAddress, - max_interest_rate: "10", + max_interest_rate: "1000", debt_issued: "100000", total_obligation: "0", total_raised: "0", @@ -306,7 +306,7 @@ describe("Issuance Tests", () => { collateral: COLLATERAL.toLowerCase(), collateral_amount: "10000", badge_address: badgeAddress, - max_interest_rate: "10", + max_interest_rate: "1000", debt_issued: "100000", total_obligation: "0", total_raised: "0", @@ -376,7 +376,7 @@ describe("Issuance Close Tests", () => { description: "testtesttesttesttest", promotion: "testtesttesttesttest", token: TOKEN_ADDRESS, - max_interest_rate: "10", + max_interest_rate: "1000", debt_issued: "100000", closes_at: closesAt, maturity_at: maturityAt, @@ -432,7 +432,7 @@ describe("Issuance Close Tests", () => { path: "order/create", data: { issuance_id: 1, - interest_rate: "9", + interest_rate: "900", }, }); @@ -476,7 +476,7 @@ describe("Issuance Close Tests", () => { const expectedCloseIssuanceNoticeOutput = encodeNoticeOutput({ payload: stringToHex( - `issuance closed - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"${TOKEN_ADDRESS.toLowerCase()}","creator":{"id":3,"role":"creator","address":"${CREATOR_ADDRESS}","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":${baseTime}}],"created_at":${baseTime},"updated_at":0},"collateral":"${COLLATERAL.toLowerCase()}","collateral_amount":"10000","badge_address":"${badgeAddress}","debt_issued":"100000","max_interest_rate":"10","total_obligation":"76300","total_raised":"70000","state":"closed","orders":[{"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"${INVESTOR_01_ADDRESS}","social_accounts":[],"created_at":${baseTime},"updated_at":0},"amount":"70000","interest_rate":"9","state":"accepted","created_at":${baseTime},"updated_at":1}],"created_at":${baseTime},"closes_at":${closesAt},"maturity_at":${maturityAt},"updated_at":1}`, + `issuance closed - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"${TOKEN_ADDRESS.toLowerCase()}","creator":{"id":3,"role":"creator","address":"${CREATOR_ADDRESS}","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":${baseTime}}],"created_at":${baseTime},"updated_at":0},"collateral":"${COLLATERAL.toLowerCase()}","collateral_amount":"10000","badge_address":"${badgeAddress}","debt_issued":"100000","max_interest_rate":"1000","total_obligation":"76300","total_raised":"70000","state":"closed","orders":[{"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"${INVESTOR_01_ADDRESS}","social_accounts":[],"created_at":${baseTime},"updated_at":0},"amount":"70000","interest_rate":"900","state":"accepted","created_at":${baseTime},"updated_at":1}],"created_at":${baseTime},"closes_at":${closesAt},"maturity_at":${maturityAt},"updated_at":1}`, ), }); expect(bytesToHex(outputs[outputs.length - 1])).toBe( @@ -575,7 +575,7 @@ describe("Issuance Execute Collateral Tests", () => { description: "testtesttesttesttest", promotion: "testtesttesttesttest", token: TOKEN_ADDRESS, - max_interest_rate: "10", + max_interest_rate: "1000", debt_issued: "100000", closes_at: closesAt, maturity_at: maturityAt, @@ -632,7 +632,7 @@ describe("Issuance Execute Collateral Tests", () => { path: "order/create", data: { issuance_id: 1, - interest_rate: "9", + interest_rate: "900", }, }); @@ -698,7 +698,7 @@ describe("Issuance Execute Collateral Tests", () => { const expectedExecuteIssuanceCollateralNoticeOutput = encodeNoticeOutput({ payload: stringToHex( - `issuance collateral executed - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"${TOKEN_ADDRESS.toLowerCase()}","creator":{"id":3,"role":"creator","address":"${CREATOR_ADDRESS}","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":${baseTime}}],"created_at":${baseTime},"updated_at":0},"collateral":"${COLLATERAL.toLowerCase()}","collateral_amount":"10000","badge_address":"${badgeAddress}","debt_issued":"100000","max_interest_rate":"10","total_obligation":"76300","total_raised":"70000","state":"collateral_executed","orders":[{"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"${INVESTOR_01_ADDRESS}","social_accounts":[],"created_at":${baseTime},"updated_at":0},"amount":"70000","interest_rate":"9","state":"settled_by_collateral","created_at":${baseTime},"updated_at":1}],"created_at":${baseTime},"closes_at":${closesAt},"maturity_at":${maturityAt},"updated_at":1}`, + `issuance collateral executed - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"${TOKEN_ADDRESS.toLowerCase()}","creator":{"id":3,"role":"creator","address":"${CREATOR_ADDRESS}","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":${baseTime}}],"created_at":${baseTime},"updated_at":0},"collateral":"${COLLATERAL.toLowerCase()}","collateral_amount":"10000","badge_address":"${badgeAddress}","debt_issued":"100000","max_interest_rate":"1000","total_obligation":"76300","total_raised":"70000","state":"collateral_executed","orders":[{"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"${INVESTOR_01_ADDRESS}","social_accounts":[],"created_at":${baseTime},"updated_at":0},"amount":"70000","interest_rate":"900","state":"settled_by_collateral","created_at":${baseTime},"updated_at":1}],"created_at":${baseTime},"closes_at":${closesAt},"maturity_at":${maturityAt},"updated_at":1}`, ), }); expect(bytesToHex(outputs[outputs.length - 1])).toBe( @@ -762,7 +762,7 @@ describe("Issuance Settle Tests", () => { description: "testtesttesttesttest", promotion: "testtesttesttesttest", token: TOKEN_ADDRESS, - max_interest_rate: "10", + max_interest_rate: "1000", debt_issued: "100000", closes_at: closesAt, maturity_at: maturityAt, @@ -818,7 +818,7 @@ describe("Issuance Settle Tests", () => { path: "order/create", data: { issuance_id: 1, - interest_rate: "9", + interest_rate: "900", }, }); @@ -937,7 +937,7 @@ describe("Issuance Settle Tests", () => { const expectedSettleIssuanceNoticeOutput = encodeNoticeOutput({ payload: stringToHex( - `issuance settled - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"${TOKEN_ADDRESS.toLowerCase()}","creator":{"id":3,"role":"creator","address":"${CREATOR_ADDRESS}","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":${baseTime}}],"created_at":${baseTime},"updated_at":0},"collateral":"${COLLATERAL.toLowerCase()}","collateral_amount":"10000","badge_address":"${badgeAddress}","debt_issued":"100000","max_interest_rate":"10","total_obligation":"76300","total_raised":"70000","state":"settled","orders":[{"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"${INVESTOR_01_ADDRESS}","social_accounts":[],"created_at":${baseTime},"updated_at":0},"amount":"70000","interest_rate":"9","state":"settled","created_at":${baseTime},"updated_at":1}],"created_at":${baseTime},"closes_at":${closesAt},"maturity_at":${maturityAt},"updated_at":1}`, + `issuance settled - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"${TOKEN_ADDRESS.toLowerCase()}","creator":{"id":3,"role":"creator","address":"${CREATOR_ADDRESS}","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":${baseTime}}],"created_at":${baseTime},"updated_at":0},"collateral":"${COLLATERAL.toLowerCase()}","collateral_amount":"10000","badge_address":"${badgeAddress}","debt_issued":"100000","max_interest_rate":"1000","total_obligation":"76300","total_raised":"70000","state":"settled","orders":[{"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"${INVESTOR_01_ADDRESS}","social_accounts":[],"created_at":${baseTime},"updated_at":0},"amount":"70000","interest_rate":"900","state":"settled","created_at":${baseTime},"updated_at":1}],"created_at":${baseTime},"closes_at":${closesAt},"maturity_at":${maturityAt},"updated_at":1}`, ), }); expect(bytesToHex(outputs[outputs.length - 1])).toBe( @@ -1029,7 +1029,7 @@ describe("Issuance with Multiple Investors Tests", () => { description: "testtesttesttesttest", promotion: "testtesttesttesttest", token: TOKEN_ADDRESS, - max_interest_rate: "10", + max_interest_rate: "1000", debt_issued: "100000", closes_at: closesAt, maturity_at: maturityAt, @@ -1058,7 +1058,7 @@ describe("Issuance with Multiple Investors Tests", () => { path: "order/create", data: { issuance_id: 1, - interest_rate: String(10 - i), + interest_rate: String((10 - i) * 100), }, }); diff --git a/test/integration/order.test.ts b/test/integration/order.test.ts index aadd3e9..58c61b8 100644 --- a/test/integration/order.test.ts +++ b/test/integration/order.test.ts @@ -69,7 +69,7 @@ describe("Order Tests", () => { description: "testtesttesttesttest", promotion: "testtesttesttesttest", token: TOKEN_ADDRESS, - max_interest_rate: "10", + max_interest_rate: "1000", debt_issued: "100000", closes_at: closesAt, maturity_at: maturityAt, @@ -117,7 +117,7 @@ describe("Order Tests", () => { path: "order/create", data: { issuance_id: 1, - interest_rate: "9", + interest_rate: "900", }, }); @@ -141,7 +141,7 @@ describe("Order Tests", () => { const expectedCreateOrderNoticeOutput = encodeNoticeOutput({ payload: stringToHex( - `order created - {"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"${INVESTOR_01_ADDRESS}","social_accounts":[],"created_at":${baseTime},"updated_at":0},"amount":"10000","interest_rate":"9","state":"pending","created_at":${baseTime}}`, + `order created - {"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"${INVESTOR_01_ADDRESS}","social_accounts":[],"created_at":${baseTime},"updated_at":0},"amount":"10000","interest_rate":"900","state":"pending","created_at":${baseTime}}`, ), }); expect(bytesToHex(outputs[0])).toBe(expectedCreateOrderNoticeOutput); @@ -173,7 +173,7 @@ describe("Order Tests", () => { updated_at: 0, }, amount: "10000", - interest_rate: "9", + interest_rate: "900", created_at: baseTime, updated_at: 0, }, @@ -209,7 +209,7 @@ describe("Order Tests", () => { updated_at: 0, }, amount: "10000", - interest_rate: "9", + interest_rate: "900", created_at: baseTime, updated_at: 0, }; @@ -245,7 +245,7 @@ describe("Order Tests", () => { updated_at: 0, }, amount: "10000", - interest_rate: "9", + interest_rate: "900", created_at: baseTime, updated_at: 0, }, @@ -282,7 +282,7 @@ describe("Order Tests", () => { updated_at: 0, }, amount: "10000", - interest_rate: "9", + interest_rate: "900", created_at: baseTime, updated_at: 0, }, diff --git a/test/mock/issuance_test.go b/test/mock/issuance_test.go index e1ac8ec..160b131 100644 --- a/test/mock/issuance_test.go +++ b/test/mock/issuance_test.go @@ -55,7 +55,7 @@ func (s *IssuanceSuite) TestCreateIssuance() { ) // create issuance - createIssuanceInput := []byte(fmt.Sprintf(`{"path":"issuance/creator/create","data":{"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","max_interest_rate":"10","debt_issued":"100000","closes_at":%d,"maturity_at":%d}}`, + createIssuanceInput := []byte(fmt.Sprintf(`{"path":"issuance/creator/create","data":{"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","max_interest_rate":"1000","debt_issued":"100000","closes_at":%d,"maturity_at":%d}}`, token, closesAt, maturityAt, @@ -63,7 +63,7 @@ func (s *IssuanceSuite) TestCreateIssuance() { createIssuanceOutput := s.Tester.DepositERC20(collateral, creator, big.NewInt(10000), createIssuanceInput) s.Len(createIssuanceOutput.Notices, 1) - expectedCreateIssuanceOutput := fmt.Sprintf(`issuance created - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"10","state":"ongoing","orders":[],"created_at":%d,"closes_at":%d,"maturity_at":%d}`, + expectedCreateIssuanceOutput := fmt.Sprintf(`issuance created - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"1000","state":"ongoing","orders":[],"created_at":%d,"closes_at":%d,"maturity_at":%d}`, token.Hex(), creator.Hex(), baseTime, @@ -128,7 +128,7 @@ func (s *IssuanceSuite) TestFindAllIssuances() { ) // create issuance - createIssuanceInput := []byte(fmt.Sprintf(`{"path":"issuance/creator/create","data":{"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","max_interest_rate":"10","debt_issued":"100000","closes_at":%d,"maturity_at":%d}}`, + createIssuanceInput := []byte(fmt.Sprintf(`{"path":"issuance/creator/create","data":{"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","max_interest_rate":"1000","debt_issued":"100000","closes_at":%d,"maturity_at":%d}}`, token, closesAt, maturityAt, @@ -136,7 +136,7 @@ func (s *IssuanceSuite) TestFindAllIssuances() { createIssuanceOutput := s.Tester.DepositERC20(collateral, creator, big.NewInt(10000), createIssuanceInput) s.Len(createIssuanceOutput.Notices, 1) - expectedCreateIssuanceOutput := fmt.Sprintf(`issuance created - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"10","state":"ongoing","orders":[],"created_at":%d,"closes_at":%d,"maturity_at":%d}`, + expectedCreateIssuanceOutput := fmt.Sprintf(`issuance created - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"1000","state":"ongoing","orders":[],"created_at":%d,"closes_at":%d,"maturity_at":%d}`, token.Hex(), creator.Hex(), baseTime, @@ -172,7 +172,7 @@ func (s *IssuanceSuite) TestFindAllIssuances() { findAllIssuancesOutput := s.Tester.Inspect(findAllIssuancesInput) s.Len(findAllIssuancesOutput.Reports, 1) - expectedFindAllIssuancesOutput := fmt.Sprintf(`[{"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"10","total_obligation":"0","total_raised":"0","state":"ongoing","orders":[],"created_at":%d,"closes_at":%d,"maturity_at":%d,"updated_at":0}]`, + expectedFindAllIssuancesOutput := fmt.Sprintf(`[{"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"1000","total_obligation":"0","total_raised":"0","state":"ongoing","orders":[],"created_at":%d,"closes_at":%d,"maturity_at":%d,"updated_at":0}]`, token.Hex(), creator.Hex(), baseTime, @@ -219,7 +219,7 @@ func (s *IssuanceSuite) TestFindIssuanceById() { ) // create issuance - createIssuanceInput := []byte(fmt.Sprintf(`{"path":"issuance/creator/create","data":{"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","max_interest_rate":"10","debt_issued":"100000","closes_at":%d,"maturity_at":%d}}`, + createIssuanceInput := []byte(fmt.Sprintf(`{"path":"issuance/creator/create","data":{"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","max_interest_rate":"1000","debt_issued":"100000","closes_at":%d,"maturity_at":%d}}`, token, closesAt, maturityAt, @@ -227,7 +227,7 @@ func (s *IssuanceSuite) TestFindIssuanceById() { createIssuanceOutput := s.Tester.DepositERC20(collateral, creator, big.NewInt(10000), createIssuanceInput) s.Len(createIssuanceOutput.Notices, 1) - expectedCreateIssuanceOutput := fmt.Sprintf(`issuance created - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"10","state":"ongoing","orders":[],"created_at":%d,"closes_at":%d,"maturity_at":%d}`, + expectedCreateIssuanceOutput := fmt.Sprintf(`issuance created - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"1000","state":"ongoing","orders":[],"created_at":%d,"closes_at":%d,"maturity_at":%d}`, token.Hex(), creator.Hex(), baseTime, @@ -263,7 +263,7 @@ func (s *IssuanceSuite) TestFindIssuanceById() { findIssuanceByIdOutput := s.Tester.Inspect(findIssuanceByIdInput) s.Len(findIssuanceByIdOutput.Reports, 1) - expectedFindIssuanceByIdOutput := fmt.Sprintf(`{"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"10","total_obligation":"0","total_raised":"0","state":"ongoing","orders":[],"created_at":%d,"closes_at":%d,"maturity_at":%d,"updated_at":0}`, + expectedFindIssuanceByIdOutput := fmt.Sprintf(`{"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"1000","total_obligation":"0","total_raised":"0","state":"ongoing","orders":[],"created_at":%d,"closes_at":%d,"maturity_at":%d,"updated_at":0}`, token.Hex(), creator.Hex(), baseTime, @@ -307,7 +307,7 @@ func (s *IssuanceSuite) TestFindIssuancesByCreatorAddress() { ) // create issuance - createIssuanceInput := []byte(fmt.Sprintf(`{"path":"issuance/creator/create","data":{"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","max_interest_rate":"10","debt_issued":"100000","closes_at":%d,"maturity_at":%d}}`, + createIssuanceInput := []byte(fmt.Sprintf(`{"path":"issuance/creator/create","data":{"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","max_interest_rate":"1000","debt_issued":"100000","closes_at":%d,"maturity_at":%d}}`, token, closesAt, maturityAt, @@ -315,7 +315,7 @@ func (s *IssuanceSuite) TestFindIssuancesByCreatorAddress() { createIssuanceOutput := s.Tester.DepositERC20(collateral, creator, big.NewInt(10000), createIssuanceInput) s.Len(createIssuanceOutput.Notices, 1) - expectedCreateIssuanceOutput := fmt.Sprintf(`issuance created - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"10","state":"ongoing","orders":[],"created_at":%d,"closes_at":%d,"maturity_at":%d}`, + expectedCreateIssuanceOutput := fmt.Sprintf(`issuance created - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"1000","state":"ongoing","orders":[],"created_at":%d,"closes_at":%d,"maturity_at":%d}`, token.Hex(), creator.Hex(), baseTime, @@ -351,7 +351,7 @@ func (s *IssuanceSuite) TestFindIssuancesByCreatorAddress() { findIssuancesByCreatorOutput := s.Tester.Inspect(findIssuancesByCreatorInput) s.Len(findIssuancesByCreatorOutput.Reports, 1) - expectedFindIssuancesByCreatorAddressOutput := fmt.Sprintf(`[{"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"10","total_obligation":"0","total_raised":"0","state":"ongoing","orders":[],"created_at":%d,"closes_at":%d,"maturity_at":%d,"updated_at":0}]`, + expectedFindIssuancesByCreatorAddressOutput := fmt.Sprintf(`[{"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"1000","total_obligation":"0","total_raised":"0","state":"ongoing","orders":[],"created_at":%d,"closes_at":%d,"maturity_at":%d,"updated_at":0}]`, token.Hex(), creator.Hex(), baseTime, @@ -434,7 +434,7 @@ func (s *IssuanceSuite) TestFindIssuancesByInvestorAddress() { ) // create issuance - createIssuanceInput := []byte(fmt.Sprintf(`{"path":"issuance/creator/create","data":{"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","max_interest_rate":"10","debt_issued":"100000","closes_at":%d,"maturity_at":%d}}`, + createIssuanceInput := []byte(fmt.Sprintf(`{"path":"issuance/creator/create","data":{"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","max_interest_rate":"1000","debt_issued":"100000","closes_at":%d,"maturity_at":%d}}`, token, closesAt, maturityAt, @@ -442,7 +442,7 @@ func (s *IssuanceSuite) TestFindIssuancesByInvestorAddress() { createIssuanceOutput := s.Tester.DepositERC20(collateral, creator, big.NewInt(10000), createIssuanceInput) s.Len(createIssuanceOutput.Notices, 1) - expectedCreateIssuanceOutput := fmt.Sprintf(`issuance created - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"10","state":"ongoing","orders":[],"created_at":%d,"closes_at":%d,"maturity_at":%d}`, + expectedCreateIssuanceOutput := fmt.Sprintf(`issuance created - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"1000","state":"ongoing","orders":[],"created_at":%d,"closes_at":%d,"maturity_at":%d}`, token.Hex(), creator.Hex(), baseTime, @@ -473,23 +473,23 @@ func (s *IssuanceSuite) TestFindIssuancesByInvestorAddress() { saltBytes := unpacked[1].([32]byte) s.Equal(common.HexToHash(strconv.Itoa(7)), common.BytesToHash(saltBytes[:])) - createOrderInput := []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"9"}}`) + createOrderInput := []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"900"}}`) createOrderOutput := s.Tester.DepositERC20(token, investor01, big.NewInt(60000), createOrderInput) s.Len(createOrderOutput.Notices, 1) - createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"8"}}`) + createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"800"}}`) createOrderOutput = s.Tester.DepositERC20(token, investor02, big.NewInt(28000), createOrderInput) s.Len(createOrderOutput.Notices, 1) - createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"4"}}`) + createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"400"}}`) createOrderOutput = s.Tester.DepositERC20(token, investor03, big.NewInt(2000), createOrderInput) s.Len(createOrderOutput.Notices, 1) - createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"6"}}`) + createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"600"}}`) createOrderOutput = s.Tester.DepositERC20(token, investor04, big.NewInt(5000), createOrderInput) s.Len(createOrderOutput.Notices, 1) - createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"4"}}`) + createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"400"}}`) createOrderOutput = s.Tester.DepositERC20(token, investor05, big.NewInt(5500), createOrderInput) s.Len(createOrderOutput.Notices, 1) @@ -500,13 +500,13 @@ func (s *IssuanceSuite) TestFindIssuancesByInvestorAddress() { closeIssuanceOutput := s.Tester.Advance(anyone, closeIssuanceInput) s.Len(closeIssuanceOutput.Notices, 1) - expectedCloseIssuanceOutput := fmt.Sprintf(`issuance closed - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"10","total_obligation":"108195","total_raised":"100000","state":"closed","orders":[`+ - `{"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"59500","interest_rate":"9","state":"partially_accepted","created_at":%d,"updated_at":%d},`+ - `{"id":2,"issuance_id":1,"investor":{"id":5,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"28000","interest_rate":"8","state":"accepted","created_at":%d,"updated_at":%d},`+ - `{"id":3,"issuance_id":1,"investor":{"id":6,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"2000","interest_rate":"4","state":"accepted","created_at":%d,"updated_at":%d},`+ - `{"id":4,"issuance_id":1,"investor":{"id":7,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"5000","interest_rate":"6","state":"accepted","created_at":%d,"updated_at":%d},`+ - `{"id":5,"issuance_id":1,"investor":{"id":8,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"5500","interest_rate":"4","state":"accepted","created_at":%d,"updated_at":%d},`+ - `{"id":6,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"500","interest_rate":"9","state":"rejected","created_at":%d,"updated_at":%d}],`+ + expectedCloseIssuanceOutput := fmt.Sprintf(`issuance closed - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"1000","total_obligation":"108195","total_raised":"100000","state":"closed","orders":[`+ + `{"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"59500","interest_rate":"900","state":"partially_accepted","created_at":%d,"updated_at":%d},`+ + `{"id":2,"issuance_id":1,"investor":{"id":5,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"28000","interest_rate":"800","state":"accepted","created_at":%d,"updated_at":%d},`+ + `{"id":3,"issuance_id":1,"investor":{"id":6,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"2000","interest_rate":"400","state":"accepted","created_at":%d,"updated_at":%d},`+ + `{"id":4,"issuance_id":1,"investor":{"id":7,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"5000","interest_rate":"600","state":"accepted","created_at":%d,"updated_at":%d},`+ + `{"id":5,"issuance_id":1,"investor":{"id":8,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"5500","interest_rate":"400","state":"accepted","created_at":%d,"updated_at":%d},`+ + `{"id":6,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"500","interest_rate":"900","state":"rejected","created_at":%d,"updated_at":%d}],`+ `"created_at":%d,"closes_at":%d,"maturity_at":%d,"updated_at":%d}`, token.Hex(), creator.Hex(), @@ -531,13 +531,13 @@ func (s *IssuanceSuite) TestFindIssuancesByInvestorAddress() { expectedWithdrawRaisedAmountOutput := fmt.Sprintf(`ERC20 withdrawn - token: %s, amount: 95000, user: %s`, token.Hex(), creator.Hex()) s.Equal(expectedWithdrawRaisedAmountOutput, string(withdrawRaisedAmountOutput.Notices[0].Payload)) - expectedFindIssuanceByCreatorOutput := fmt.Sprintf(`[{"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"10","total_obligation":"108195","total_raised":"100000","state":"closed","orders":[`+ - `{"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"59500","interest_rate":"9","state":"partially_accepted","created_at":%d,"updated_at":%d},`+ - `{"id":2,"issuance_id":1,"investor":{"id":5,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"28000","interest_rate":"8","state":"accepted","created_at":%d,"updated_at":%d},`+ - `{"id":3,"issuance_id":1,"investor":{"id":6,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"2000","interest_rate":"4","state":"accepted","created_at":%d,"updated_at":%d},`+ - `{"id":4,"issuance_id":1,"investor":{"id":7,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"5000","interest_rate":"6","state":"accepted","created_at":%d,"updated_at":%d},`+ - `{"id":5,"issuance_id":1,"investor":{"id":8,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"5500","interest_rate":"4","state":"accepted","created_at":%d,"updated_at":%d},`+ - `{"id":6,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"500","interest_rate":"9","state":"rejected","created_at":%d,"updated_at":%d}],`+ + expectedFindIssuanceByCreatorOutput := fmt.Sprintf(`[{"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"1000","total_obligation":"108195","total_raised":"100000","state":"closed","orders":[`+ + `{"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"59500","interest_rate":"900","state":"partially_accepted","created_at":%d,"updated_at":%d},`+ + `{"id":2,"issuance_id":1,"investor":{"id":5,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"28000","interest_rate":"800","state":"accepted","created_at":%d,"updated_at":%d},`+ + `{"id":3,"issuance_id":1,"investor":{"id":6,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"2000","interest_rate":"400","state":"accepted","created_at":%d,"updated_at":%d},`+ + `{"id":4,"issuance_id":1,"investor":{"id":7,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"5000","interest_rate":"600","state":"accepted","created_at":%d,"updated_at":%d},`+ + `{"id":5,"issuance_id":1,"investor":{"id":8,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"5500","interest_rate":"400","state":"accepted","created_at":%d,"updated_at":%d},`+ + `{"id":6,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"500","interest_rate":"900","state":"rejected","created_at":%d,"updated_at":%d}],`+ `"created_at":%d,"closes_at":%d,"maturity_at":%d,"updated_at":%d}]`, token.Hex(), creator.Hex(), @@ -640,7 +640,7 @@ func (s *IssuanceSuite) TestCloseIssuance() { ) // create issuance - createIssuanceInput := []byte(fmt.Sprintf(`{"path":"issuance/creator/create","data":{"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","max_interest_rate":"10","debt_issued":"100000","closes_at":%d,"maturity_at":%d}}`, + createIssuanceInput := []byte(fmt.Sprintf(`{"path":"issuance/creator/create","data":{"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","max_interest_rate":"1000","debt_issued":"100000","closes_at":%d,"maturity_at":%d}}`, token, closesAt, maturityAt, @@ -648,7 +648,7 @@ func (s *IssuanceSuite) TestCloseIssuance() { createIssuanceOutput := s.Tester.DepositERC20(collateral, creator, big.NewInt(10000), createIssuanceInput) s.Len(createIssuanceOutput.Notices, 1) - expectedCreateIssuanceOutput := fmt.Sprintf(`issuance created - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"10","state":"ongoing","orders":[],"created_at":%d,"closes_at":%d,"maturity_at":%d}`, + expectedCreateIssuanceOutput := fmt.Sprintf(`issuance created - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"1000","state":"ongoing","orders":[],"created_at":%d,"closes_at":%d,"maturity_at":%d}`, token.Hex(), creator.Hex(), baseTime, @@ -679,23 +679,23 @@ func (s *IssuanceSuite) TestCloseIssuance() { saltBytes := unpacked[1].([32]byte) s.Equal(common.HexToHash(strconv.Itoa(7)), common.BytesToHash(saltBytes[:])) - createOrderInput := []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"9"}}`) + createOrderInput := []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"900"}}`) createOrderOutput := s.Tester.DepositERC20(token, investor01, big.NewInt(60000), createOrderInput) s.Len(createOrderOutput.Notices, 1) - createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"8"}}`) + createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"800"}}`) createOrderOutput = s.Tester.DepositERC20(token, investor02, big.NewInt(28000), createOrderInput) s.Len(createOrderOutput.Notices, 1) - createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"4"}}`) + createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"400"}}`) createOrderOutput = s.Tester.DepositERC20(token, investor03, big.NewInt(2000), createOrderInput) s.Len(createOrderOutput.Notices, 1) - createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"6"}}`) + createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"600"}}`) createOrderOutput = s.Tester.DepositERC20(token, investor04, big.NewInt(5000), createOrderInput) s.Len(createOrderOutput.Notices, 1) - createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"4"}}`) + createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"400"}}`) createOrderOutput = s.Tester.DepositERC20(token, investor05, big.NewInt(5500), createOrderInput) s.Len(createOrderOutput.Notices, 1) @@ -706,13 +706,13 @@ func (s *IssuanceSuite) TestCloseIssuance() { closeIssuanceOutput := s.Tester.Advance(anyone, closeIssuanceInput) s.Len(closeIssuanceOutput.Notices, 1) - expectedCloseIssuanceOutput := fmt.Sprintf(`issuance closed - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"10","total_obligation":"108195","total_raised":"100000","state":"closed","orders":[`+ - `{"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"59500","interest_rate":"9","state":"partially_accepted","created_at":%d,"updated_at":%d},`+ - `{"id":2,"issuance_id":1,"investor":{"id":5,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"28000","interest_rate":"8","state":"accepted","created_at":%d,"updated_at":%d},`+ - `{"id":3,"issuance_id":1,"investor":{"id":6,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"2000","interest_rate":"4","state":"accepted","created_at":%d,"updated_at":%d},`+ - `{"id":4,"issuance_id":1,"investor":{"id":7,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"5000","interest_rate":"6","state":"accepted","created_at":%d,"updated_at":%d},`+ - `{"id":5,"issuance_id":1,"investor":{"id":8,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"5500","interest_rate":"4","state":"accepted","created_at":%d,"updated_at":%d},`+ - `{"id":6,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"500","interest_rate":"9","state":"rejected","created_at":%d,"updated_at":%d}],`+ + expectedCloseIssuanceOutput := fmt.Sprintf(`issuance closed - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"1000","total_obligation":"108195","total_raised":"100000","state":"closed","orders":[`+ + `{"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"59500","interest_rate":"900","state":"partially_accepted","created_at":%d,"updated_at":%d},`+ + `{"id":2,"issuance_id":1,"investor":{"id":5,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"28000","interest_rate":"800","state":"accepted","created_at":%d,"updated_at":%d},`+ + `{"id":3,"issuance_id":1,"investor":{"id":6,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"2000","interest_rate":"400","state":"accepted","created_at":%d,"updated_at":%d},`+ + `{"id":4,"issuance_id":1,"investor":{"id":7,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"5000","interest_rate":"600","state":"accepted","created_at":%d,"updated_at":%d},`+ + `{"id":5,"issuance_id":1,"investor":{"id":8,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"5500","interest_rate":"400","state":"accepted","created_at":%d,"updated_at":%d},`+ + `{"id":6,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"500","interest_rate":"900","state":"rejected","created_at":%d,"updated_at":%d}],`+ `"created_at":%d,"closes_at":%d,"maturity_at":%d,"updated_at":%d}`, token.Hex(), creator.Hex(), @@ -920,7 +920,7 @@ func (s *IssuanceSuite) TestExecuteIssuanceCollateral() { ) // create issuance - createIssuanceInput := []byte(fmt.Sprintf(`{"path":"issuance/creator/create","data":{"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","max_interest_rate":"10","debt_issued":"100000","closes_at":%d,"maturity_at":%d}}`, + createIssuanceInput := []byte(fmt.Sprintf(`{"path":"issuance/creator/create","data":{"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","max_interest_rate":"1000","debt_issued":"100000","closes_at":%d,"maturity_at":%d}}`, token, closesAt, maturityAt, @@ -928,7 +928,7 @@ func (s *IssuanceSuite) TestExecuteIssuanceCollateral() { createIssuanceOutput := s.Tester.DepositERC20(collateral, creator, big.NewInt(10000), createIssuanceInput) s.Len(createIssuanceOutput.Notices, 1) - expectedCreateIssuanceOutput := fmt.Sprintf(`issuance created - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"10","state":"ongoing","orders":[],"created_at":%d,"closes_at":%d,"maturity_at":%d}`, + expectedCreateIssuanceOutput := fmt.Sprintf(`issuance created - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"1000","state":"ongoing","orders":[],"created_at":%d,"closes_at":%d,"maturity_at":%d}`, token.Hex(), creator.Hex(), baseTime, @@ -959,23 +959,23 @@ func (s *IssuanceSuite) TestExecuteIssuanceCollateral() { saltBytes := unpacked[1].([32]byte) s.Equal(common.HexToHash(strconv.Itoa(7)), common.BytesToHash(saltBytes[:])) - createOrderInput := []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"9"}}`) + createOrderInput := []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"900"}}`) createOrderOutput := s.Tester.DepositERC20(token, investor01, big.NewInt(60000), createOrderInput) s.Len(createOrderOutput.Notices, 1) - createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"8"}}`) + createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"800"}}`) createOrderOutput = s.Tester.DepositERC20(token, investor02, big.NewInt(28000), createOrderInput) s.Len(createOrderOutput.Notices, 1) - createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"4"}}`) + createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"400"}}`) createOrderOutput = s.Tester.DepositERC20(token, investor03, big.NewInt(2000), createOrderInput) s.Len(createOrderOutput.Notices, 1) - createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"6"}}`) + createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"600"}}`) createOrderOutput = s.Tester.DepositERC20(token, investor04, big.NewInt(5000), createOrderInput) s.Len(createOrderOutput.Notices, 1) - createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"4"}}`) + createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"400"}}`) createOrderOutput = s.Tester.DepositERC20(token, investor05, big.NewInt(5500), createOrderInput) s.Len(createOrderOutput.Notices, 1) @@ -986,13 +986,13 @@ func (s *IssuanceSuite) TestExecuteIssuanceCollateral() { closeIssuanceOutput := s.Tester.Advance(anyone, closeIssuanceInput) s.Len(closeIssuanceOutput.Notices, 1) - expectedCloseIssuanceOutput := fmt.Sprintf(`issuance closed - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"10","total_obligation":"108195","total_raised":"100000","state":"closed","orders":[`+ - `{"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"59500","interest_rate":"9","state":"partially_accepted","created_at":%d,"updated_at":%d},`+ - `{"id":2,"issuance_id":1,"investor":{"id":5,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"28000","interest_rate":"8","state":"accepted","created_at":%d,"updated_at":%d},`+ - `{"id":3,"issuance_id":1,"investor":{"id":6,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"2000","interest_rate":"4","state":"accepted","created_at":%d,"updated_at":%d},`+ - `{"id":4,"issuance_id":1,"investor":{"id":7,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"5000","interest_rate":"6","state":"accepted","created_at":%d,"updated_at":%d},`+ - `{"id":5,"issuance_id":1,"investor":{"id":8,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"5500","interest_rate":"4","state":"accepted","created_at":%d,"updated_at":%d},`+ - `{"id":6,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"500","interest_rate":"9","state":"rejected","created_at":%d,"updated_at":%d}],`+ + expectedCloseIssuanceOutput := fmt.Sprintf(`issuance closed - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"1000","total_obligation":"108195","total_raised":"100000","state":"closed","orders":[`+ + `{"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"59500","interest_rate":"900","state":"partially_accepted","created_at":%d,"updated_at":%d},`+ + `{"id":2,"issuance_id":1,"investor":{"id":5,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"28000","interest_rate":"800","state":"accepted","created_at":%d,"updated_at":%d},`+ + `{"id":3,"issuance_id":1,"investor":{"id":6,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"2000","interest_rate":"400","state":"accepted","created_at":%d,"updated_at":%d},`+ + `{"id":4,"issuance_id":1,"investor":{"id":7,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"5000","interest_rate":"600","state":"accepted","created_at":%d,"updated_at":%d},`+ + `{"id":5,"issuance_id":1,"investor":{"id":8,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"5500","interest_rate":"400","state":"accepted","created_at":%d,"updated_at":%d},`+ + `{"id":6,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"500","interest_rate":"900","state":"rejected","created_at":%d,"updated_at":%d}],`+ `"created_at":%d,"closes_at":%d,"maturity_at":%d,"updated_at":%d}`, token.Hex(), creator.Hex(), @@ -1022,13 +1022,13 @@ func (s *IssuanceSuite) TestExecuteIssuanceCollateral() { findIssuanceByIdOutput := s.Tester.Inspect(findIssuanceByIdInput) s.Len(findIssuanceByIdOutput.Reports, 1) - expectedFindIssuanceByCreatorOutput := fmt.Sprintf(`[{"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"10","total_obligation":"108195","total_raised":"100000","state":"closed","orders":[`+ - `{"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"59500","interest_rate":"9","state":"partially_accepted","created_at":%d,"updated_at":%d},`+ - `{"id":2,"issuance_id":1,"investor":{"id":5,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"28000","interest_rate":"8","state":"accepted","created_at":%d,"updated_at":%d},`+ - `{"id":3,"issuance_id":1,"investor":{"id":6,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"2000","interest_rate":"4","state":"accepted","created_at":%d,"updated_at":%d},`+ - `{"id":4,"issuance_id":1,"investor":{"id":7,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"5000","interest_rate":"6","state":"accepted","created_at":%d,"updated_at":%d},`+ - `{"id":5,"issuance_id":1,"investor":{"id":8,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"5500","interest_rate":"4","state":"accepted","created_at":%d,"updated_at":%d},`+ - `{"id":6,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"500","interest_rate":"9","state":"rejected","created_at":%d,"updated_at":%d}],`+ + expectedFindIssuanceByCreatorOutput := fmt.Sprintf(`[{"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"1000","total_obligation":"108195","total_raised":"100000","state":"closed","orders":[`+ + `{"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"59500","interest_rate":"900","state":"partially_accepted","created_at":%d,"updated_at":%d},`+ + `{"id":2,"issuance_id":1,"investor":{"id":5,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"28000","interest_rate":"800","state":"accepted","created_at":%d,"updated_at":%d},`+ + `{"id":3,"issuance_id":1,"investor":{"id":6,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"2000","interest_rate":"400","state":"accepted","created_at":%d,"updated_at":%d},`+ + `{"id":4,"issuance_id":1,"investor":{"id":7,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"5000","interest_rate":"600","state":"accepted","created_at":%d,"updated_at":%d},`+ + `{"id":5,"issuance_id":1,"investor":{"id":8,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"5500","interest_rate":"400","state":"accepted","created_at":%d,"updated_at":%d},`+ + `{"id":6,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"500","interest_rate":"900","state":"rejected","created_at":%d,"updated_at":%d}],`+ `"created_at":%d,"closes_at":%d,"maturity_at":%d,"updated_at":%d}]`, token.Hex(), creator.Hex(), @@ -1058,13 +1058,13 @@ func (s *IssuanceSuite) TestExecuteIssuanceCollateral() { updatedAt := baseTime + 11 - expectedExecuteIssuanceCollateralOutput := fmt.Sprintf(`issuance collateral executed - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"10","total_obligation":"108195","total_raised":"100000","state":"collateral_executed","orders":[`+ - `{"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"59500","interest_rate":"9","state":"settled_by_collateral","created_at":%d,"updated_at":%d},`+ - `{"id":2,"issuance_id":1,"investor":{"id":5,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"28000","interest_rate":"8","state":"settled_by_collateral","created_at":%d,"updated_at":%d},`+ - `{"id":3,"issuance_id":1,"investor":{"id":6,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"2000","interest_rate":"4","state":"settled_by_collateral","created_at":%d,"updated_at":%d},`+ - `{"id":4,"issuance_id":1,"investor":{"id":7,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"5000","interest_rate":"6","state":"settled_by_collateral","created_at":%d,"updated_at":%d},`+ - `{"id":5,"issuance_id":1,"investor":{"id":8,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"5500","interest_rate":"4","state":"settled_by_collateral","created_at":%d,"updated_at":%d},`+ - `{"id":6,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"500","interest_rate":"9","state":"rejected","created_at":%d,"updated_at":%d}],`+ + expectedExecuteIssuanceCollateralOutput := fmt.Sprintf(`issuance collateral executed - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"1000","total_obligation":"108195","total_raised":"100000","state":"collateral_executed","orders":[`+ + `{"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"59500","interest_rate":"900","state":"settled_by_collateral","created_at":%d,"updated_at":%d},`+ + `{"id":2,"issuance_id":1,"investor":{"id":5,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"28000","interest_rate":"800","state":"settled_by_collateral","created_at":%d,"updated_at":%d},`+ + `{"id":3,"issuance_id":1,"investor":{"id":6,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"2000","interest_rate":"400","state":"settled_by_collateral","created_at":%d,"updated_at":%d},`+ + `{"id":4,"issuance_id":1,"investor":{"id":7,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"5000","interest_rate":"600","state":"settled_by_collateral","created_at":%d,"updated_at":%d},`+ + `{"id":5,"issuance_id":1,"investor":{"id":8,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"5500","interest_rate":"400","state":"settled_by_collateral","created_at":%d,"updated_at":%d},`+ + `{"id":6,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"500","interest_rate":"900","state":"rejected","created_at":%d,"updated_at":%d}],`+ `"created_at":%d,"closes_at":%d,"maturity_at":%d,"updated_at":%d}`, token.Hex(), creator.Hex(), @@ -1272,7 +1272,7 @@ func (s *IssuanceSuite) TestSettleIssuance() { ) // create issuance - createIssuanceInput := []byte(fmt.Sprintf(`{"path":"issuance/creator/create","data":{"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","max_interest_rate":"10","debt_issued":"100000","closes_at":%d,"maturity_at":%d}}`, + createIssuanceInput := []byte(fmt.Sprintf(`{"path":"issuance/creator/create","data":{"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","max_interest_rate":"1000","debt_issued":"100000","closes_at":%d,"maturity_at":%d}}`, token, closesAt, maturityAt, @@ -1280,7 +1280,7 @@ func (s *IssuanceSuite) TestSettleIssuance() { createIssuanceOutput := s.Tester.DepositERC20(collateral, creator, big.NewInt(10000), createIssuanceInput) s.Len(createIssuanceOutput.Notices, 1) - expectedCreateIssuanceOutput := fmt.Sprintf(`issuance created - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"10","state":"ongoing","orders":[],"created_at":%d,"closes_at":%d,"maturity_at":%d}`, + expectedCreateIssuanceOutput := fmt.Sprintf(`issuance created - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"1000","state":"ongoing","orders":[],"created_at":%d,"closes_at":%d,"maturity_at":%d}`, token.Hex(), creator.Hex(), baseTime, @@ -1309,23 +1309,23 @@ func (s *IssuanceSuite) TestSettleIssuance() { s.Require().NoError(err) s.Equal(applicationAddress, unpacked[0]) - createOrderInput := []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"9"}}`) + createOrderInput := []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"900"}}`) createOrderOutput := s.Tester.DepositERC20(token, investor01, big.NewInt(60000), createOrderInput) s.Len(createOrderOutput.Notices, 1) - createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"8"}}`) + createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"800"}}`) createOrderOutput = s.Tester.DepositERC20(token, investor02, big.NewInt(28000), createOrderInput) s.Len(createOrderOutput.Notices, 1) - createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"4"}}`) + createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"400"}}`) createOrderOutput = s.Tester.DepositERC20(token, investor03, big.NewInt(2000), createOrderInput) s.Len(createOrderOutput.Notices, 1) - createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"6"}}`) + createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"600"}}`) createOrderOutput = s.Tester.DepositERC20(token, investor04, big.NewInt(5000), createOrderInput) s.Len(createOrderOutput.Notices, 1) - createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"4"}}`) + createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"400"}}`) createOrderOutput = s.Tester.DepositERC20(token, investor05, big.NewInt(5500), createOrderInput) s.Len(createOrderOutput.Notices, 1) @@ -1336,13 +1336,13 @@ func (s *IssuanceSuite) TestSettleIssuance() { closeIssuanceOutput := s.Tester.Advance(anyone, closeIssuanceInput) s.Len(closeIssuanceOutput.Notices, 1) - expectedCloseIssuanceOutput := fmt.Sprintf(`issuance closed - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"10","total_obligation":"108195","total_raised":"100000","state":"closed","orders":[`+ - `{"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"59500","interest_rate":"9","state":"partially_accepted","created_at":%d,"updated_at":%d},`+ - `{"id":2,"issuance_id":1,"investor":{"id":5,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"28000","interest_rate":"8","state":"accepted","created_at":%d,"updated_at":%d},`+ - `{"id":3,"issuance_id":1,"investor":{"id":6,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"2000","interest_rate":"4","state":"accepted","created_at":%d,"updated_at":%d},`+ - `{"id":4,"issuance_id":1,"investor":{"id":7,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"5000","interest_rate":"6","state":"accepted","created_at":%d,"updated_at":%d},`+ - `{"id":5,"issuance_id":1,"investor":{"id":8,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"5500","interest_rate":"4","state":"accepted","created_at":%d,"updated_at":%d},`+ - `{"id":6,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"500","interest_rate":"9","state":"rejected","created_at":%d,"updated_at":%d}],`+ + expectedCloseIssuanceOutput := fmt.Sprintf(`issuance closed - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"1000","total_obligation":"108195","total_raised":"100000","state":"closed","orders":[`+ + `{"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"59500","interest_rate":"900","state":"partially_accepted","created_at":%d,"updated_at":%d},`+ + `{"id":2,"issuance_id":1,"investor":{"id":5,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"28000","interest_rate":"800","state":"accepted","created_at":%d,"updated_at":%d},`+ + `{"id":3,"issuance_id":1,"investor":{"id":6,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"2000","interest_rate":"400","state":"accepted","created_at":%d,"updated_at":%d},`+ + `{"id":4,"issuance_id":1,"investor":{"id":7,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"5000","interest_rate":"600","state":"accepted","created_at":%d,"updated_at":%d},`+ + `{"id":5,"issuance_id":1,"investor":{"id":8,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"5500","interest_rate":"400","state":"accepted","created_at":%d,"updated_at":%d},`+ + `{"id":6,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"500","interest_rate":"900","state":"rejected","created_at":%d,"updated_at":%d}],`+ `"created_at":%d,"closes_at":%d,"maturity_at":%d,"updated_at":%d}`, token.Hex(), creator.Hex(), @@ -1445,13 +1445,13 @@ func (s *IssuanceSuite) TestSettleIssuance() { settledAt := baseTime + 10 - expectedSettleIssuanceOutput := fmt.Sprintf(`issuance settled - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"10","total_obligation":"108195","total_raised":"100000","state":"settled","orders":[`+ - `{"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"59500","interest_rate":"9","state":"settled","created_at":%d,"updated_at":%d},`+ - `{"id":2,"issuance_id":1,"investor":{"id":5,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"28000","interest_rate":"8","state":"settled","created_at":%d,"updated_at":%d},`+ - `{"id":3,"issuance_id":1,"investor":{"id":6,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"2000","interest_rate":"4","state":"settled","created_at":%d,"updated_at":%d},`+ - `{"id":4,"issuance_id":1,"investor":{"id":7,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"5000","interest_rate":"6","state":"settled","created_at":%d,"updated_at":%d},`+ - `{"id":5,"issuance_id":1,"investor":{"id":8,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"5500","interest_rate":"4","state":"settled","created_at":%d,"updated_at":%d},`+ - `{"id":6,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"500","interest_rate":"9","state":"rejected","created_at":%d,"updated_at":%d}],`+ + expectedSettleIssuanceOutput := fmt.Sprintf(`issuance settled - {"id":1,"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","creator":{"id":3,"role":"creator","address":"%s","social_accounts":[{"id":1,"user_id":3,"username":"test","platform":"twitter","created_at":%d}],"created_at":%d,"updated_at":0},"collateral":"%s","collateral_amount":"10000","badge_address":"%s","debt_issued":"100000","max_interest_rate":"1000","total_obligation":"108195","total_raised":"100000","state":"settled","orders":[`+ + `{"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"59500","interest_rate":"900","state":"settled","created_at":%d,"updated_at":%d},`+ + `{"id":2,"issuance_id":1,"investor":{"id":5,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"28000","interest_rate":"800","state":"settled","created_at":%d,"updated_at":%d},`+ + `{"id":3,"issuance_id":1,"investor":{"id":6,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"2000","interest_rate":"400","state":"settled","created_at":%d,"updated_at":%d},`+ + `{"id":4,"issuance_id":1,"investor":{"id":7,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"5000","interest_rate":"600","state":"settled","created_at":%d,"updated_at":%d},`+ + `{"id":5,"issuance_id":1,"investor":{"id":8,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"5500","interest_rate":"400","state":"settled","created_at":%d,"updated_at":%d},`+ + `{"id":6,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"500","interest_rate":"900","state":"rejected","created_at":%d,"updated_at":%d}],`+ `"created_at":%d,"closes_at":%d,"maturity_at":%d,"updated_at":%d}`, token.Hex(), creator.Hex(), diff --git a/test/mock/order_test.go b/test/mock/order_test.go index 09e4bad..5a26abb 100644 --- a/test/mock/order_test.go +++ b/test/mock/order_test.go @@ -30,7 +30,7 @@ func (s *OrderSuite) TestCreateOrder() { s.Tester.Advance(verifier, createSocialAccountInput) // create issuance - createIssuanceInput := []byte(fmt.Sprintf(`{"path":"issuance/creator/create","data":{"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","max_interest_rate":"10","debt_issued":"100000","closes_at":%d,"maturity_at":%d}}`, + createIssuanceInput := []byte(fmt.Sprintf(`{"path":"issuance/creator/create","data":{"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","max_interest_rate":"1000","debt_issued":"100000","closes_at":%d,"maturity_at":%d}}`, token, closesAt, maturityAt, @@ -42,11 +42,11 @@ func (s *OrderSuite) TestCreateOrder() { s.Tester.Advance(admin, createInvestorInput) // create order - createOrderInput := []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"9"}}`) + createOrderInput := []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"900"}}`) createOrderOutput := s.Tester.DepositERC20(token, investor01, big.NewInt(10000), createOrderInput) s.Len(createOrderOutput.Notices, 1) - expectedCreateOrderOutput := fmt.Sprintf(`order created - {"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"10000","interest_rate":"9","state":"pending","created_at":%d}`, + expectedCreateOrderOutput := fmt.Sprintf(`order created - {"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"10000","interest_rate":"900","state":"pending","created_at":%d}`, investor01, baseTime, baseTime) @@ -65,7 +65,7 @@ func (s *OrderSuite) TestFindAllOrders() { createSocialAccountInput := []byte(fmt.Sprintf(`{"path":"social/verifier/create","data":{"address":"%s","username":"test","platform":"twitter"}}`, creator)) s.Tester.Advance(verifier, createSocialAccountInput) - createIssuanceInput := []byte(fmt.Sprintf(`{"path":"issuance/creator/create","data":{"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","max_interest_rate":"10","debt_issued":"100000","closes_at":%d,"maturity_at":%d}}`, + createIssuanceInput := []byte(fmt.Sprintf(`{"path":"issuance/creator/create","data":{"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","max_interest_rate":"1000","debt_issued":"100000","closes_at":%d,"maturity_at":%d}}`, token, closesAt, maturityAt, @@ -80,10 +80,10 @@ func (s *OrderSuite) TestFindAllOrders() { s.Tester.Advance(admin, createInvestorInput) // Create orders - createOrderInput := []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"9"}}`) + createOrderInput := []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"900"}}`) s.Tester.DepositERC20(token, investor01, big.NewInt(10000), createOrderInput) - createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"8"}}`) + createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"800"}}`) s.Tester.DepositERC20(token, investor02, big.NewInt(20000), createOrderInput) // Find all orders @@ -91,7 +91,7 @@ func (s *OrderSuite) TestFindAllOrders() { findAllOrdersOutput := s.Tester.Inspect(findAllOrdersInput) s.Len(findAllOrdersOutput.Reports, 1) - expectedFindAllOrdersOutput := fmt.Sprintf(`[{"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"10000","interest_rate":"9","state":"pending","created_at":%d,"updated_at":0},{"id":2,"issuance_id":1,"investor":{"id":5,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"20000","interest_rate":"8","state":"pending","created_at":%d,"updated_at":0}]`, + expectedFindAllOrdersOutput := fmt.Sprintf(`[{"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"10000","interest_rate":"900","state":"pending","created_at":%d,"updated_at":0},{"id":2,"issuance_id":1,"investor":{"id":5,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"20000","interest_rate":"800","state":"pending","created_at":%d,"updated_at":0}]`, investor01, baseTime, baseTime, investor02, baseTime, baseTime) s.Equal(expectedFindAllOrdersOutput, string(findAllOrdersOutput.Reports[0].Payload)) @@ -109,7 +109,7 @@ func (s *OrderSuite) TestFindOrderById() { createSocialAccountInput := []byte(fmt.Sprintf(`{"path":"social/verifier/create","data":{"address":"%s","username":"test","platform":"twitter"}}`, creator)) s.Tester.Advance(verifier, createSocialAccountInput) - createIssuanceInput := []byte(fmt.Sprintf(`{"path":"issuance/creator/create","data":{"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","max_interest_rate":"10","debt_issued":"100000","closes_at":%d,"maturity_at":%d}}`, + createIssuanceInput := []byte(fmt.Sprintf(`{"path":"issuance/creator/create","data":{"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","max_interest_rate":"1000","debt_issued":"100000","closes_at":%d,"maturity_at":%d}}`, token, closesAt, maturityAt, @@ -119,7 +119,7 @@ func (s *OrderSuite) TestFindOrderById() { createInvestorInput := []byte(fmt.Sprintf(`{"path":"user/admin/create","data":{"address":"%s","role":"investor"}}`, investor01)) s.Tester.Advance(admin, createInvestorInput) - createOrderInput := []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"9"}}`) + createOrderInput := []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"900"}}`) s.Tester.DepositERC20(token, investor01, big.NewInt(10000), createOrderInput) // Find order by id @@ -127,7 +127,7 @@ func (s *OrderSuite) TestFindOrderById() { findOrderByIdOutput := s.Tester.Inspect(findOrderByIdInput) s.Len(findOrderByIdOutput.Reports, 1) - expectedFindOrderByIdOutput := fmt.Sprintf(`{"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"10000","interest_rate":"9","state":"pending","created_at":%d,"updated_at":0}`, + expectedFindOrderByIdOutput := fmt.Sprintf(`{"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"10000","interest_rate":"900","state":"pending","created_at":%d,"updated_at":0}`, investor01, baseTime, baseTime) s.Equal(expectedFindOrderByIdOutput, string(findOrderByIdOutput.Reports[0].Payload)) } @@ -144,7 +144,7 @@ func (s *OrderSuite) TestFindOrdersByIssuanceId() { createSocialAccountInput := []byte(fmt.Sprintf(`{"path":"social/verifier/create","data":{"address":"%s","username":"test","platform":"twitter"}}`, creator)) s.Tester.Advance(verifier, createSocialAccountInput) - createIssuanceInput := []byte(fmt.Sprintf(`{"path":"issuance/creator/create","data":{"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","max_interest_rate":"10","debt_issued":"100000","closes_at":%d,"maturity_at":%d}}`, + createIssuanceInput := []byte(fmt.Sprintf(`{"path":"issuance/creator/create","data":{"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","max_interest_rate":"1000","debt_issued":"100000","closes_at":%d,"maturity_at":%d}}`, token, closesAt, maturityAt, @@ -157,10 +157,10 @@ func (s *OrderSuite) TestFindOrdersByIssuanceId() { createInvestorInput = []byte(fmt.Sprintf(`{"path":"user/admin/create","data":{"address":"%s","role":"investor"}}`, investor02)) s.Tester.Advance(admin, createInvestorInput) - createOrderInput := []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"9"}}`) + createOrderInput := []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"900"}}`) s.Tester.DepositERC20(token, investor01, big.NewInt(10000), createOrderInput) - createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"8"}}`) + createOrderInput = []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"800"}}`) s.Tester.DepositERC20(token, investor02, big.NewInt(20000), createOrderInput) // Find orders by issuance id @@ -168,7 +168,7 @@ func (s *OrderSuite) TestFindOrdersByIssuanceId() { findOrdersByIssuanceIdOutput := s.Tester.Inspect(findOrdersByIssuanceIdInput) s.Len(findOrdersByIssuanceIdOutput.Reports, 1) - expectedFindOrdersByIssuanceIdOutput := fmt.Sprintf(`[{"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"10000","interest_rate":"9","state":"pending","created_at":%d,"updated_at":0},{"id":2,"issuance_id":1,"investor":{"id":5,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"20000","interest_rate":"8","state":"pending","created_at":%d,"updated_at":0}]`, + expectedFindOrdersByIssuanceIdOutput := fmt.Sprintf(`[{"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"10000","interest_rate":"900","state":"pending","created_at":%d,"updated_at":0},{"id":2,"issuance_id":1,"investor":{"id":5,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"20000","interest_rate":"800","state":"pending","created_at":%d,"updated_at":0}]`, investor01, baseTime, baseTime, investor02, baseTime, baseTime) s.Equal(expectedFindOrdersByIssuanceIdOutput, string(findOrdersByIssuanceIdOutput.Reports[0].Payload)) @@ -186,7 +186,7 @@ func (s *OrderSuite) TestFindOrdersByInvestorAddress() { createSocialAccountInput := []byte(fmt.Sprintf(`{"path":"social/verifier/create","data":{"address":"%s","username":"test","platform":"twitter"}}`, creator)) s.Tester.Advance(verifier, createSocialAccountInput) - createIssuanceInput := []byte(fmt.Sprintf(`{"path":"issuance/creator/create","data":{"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","max_interest_rate":"10","debt_issued":"100000","closes_at":%d,"maturity_at":%d}}`, + createIssuanceInput := []byte(fmt.Sprintf(`{"path":"issuance/creator/create","data":{"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","max_interest_rate":"1000","debt_issued":"100000","closes_at":%d,"maturity_at":%d}}`, token, closesAt, maturityAt, @@ -196,7 +196,7 @@ func (s *OrderSuite) TestFindOrdersByInvestorAddress() { createInvestorInput := []byte(fmt.Sprintf(`{"path":"user/admin/create","data":{"address":"%s","role":"investor"}}`, investor01)) s.Tester.Advance(admin, createInvestorInput) - createOrderInput := []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"9"}}`) + createOrderInput := []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"900"}}`) s.Tester.DepositERC20(token, investor01, big.NewInt(10000), createOrderInput) // Find orders by investor address @@ -204,7 +204,7 @@ func (s *OrderSuite) TestFindOrdersByInvestorAddress() { findOrdersByInvestorAddressOutput := s.Tester.Inspect(findOrdersByInvestorAddressInput) s.Len(findOrdersByInvestorAddressOutput.Reports, 1) - expectedFindOrdersByInvestorAddressOutput := fmt.Sprintf(`[{"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"10000","interest_rate":"9","state":"pending","created_at":%d,"updated_at":0}]`, + expectedFindOrdersByInvestorAddressOutput := fmt.Sprintf(`[{"id":1,"issuance_id":1,"investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"10000","interest_rate":"900","state":"pending","created_at":%d,"updated_at":0}]`, investor01, baseTime, baseTime) s.Equal(expectedFindOrdersByInvestorAddressOutput, string(findOrdersByInvestorAddressOutput.Reports[0].Payload)) } @@ -221,7 +221,7 @@ func (s *OrderSuite) TestCancelOrder() { createSocialAccountInput := []byte(fmt.Sprintf(`{"path":"social/verifier/create","data":{"address":"%s","username":"test","platform":"twitter"}}`, creator)) s.Tester.Advance(verifier, createSocialAccountInput) - createIssuanceInput := []byte(fmt.Sprintf(`{"path":"issuance/creator/create","data":{"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","max_interest_rate":"10","debt_issued":"100000","closes_at":%d,"maturity_at":%d}}`, + createIssuanceInput := []byte(fmt.Sprintf(`{"path":"issuance/creator/create","data":{"title":"test","description":"testtesttesttesttest","promotion":"testtesttesttesttest","token":"%s","max_interest_rate":"1000","debt_issued":"100000","closes_at":%d,"maturity_at":%d}}`, token, closesAt, maturityAt, @@ -231,7 +231,7 @@ func (s *OrderSuite) TestCancelOrder() { createInvestorInput := []byte(fmt.Sprintf(`{"path":"user/admin/create","data":{"address":"%s","role":"investor"}}`, investor01)) s.Tester.Advance(admin, createInvestorInput) - createOrderInput := []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"9"}}`) + createOrderInput := []byte(`{"path": "order/create", "data": {"issuance_id":1,"interest_rate":"900"}}`) s.Tester.DepositERC20(token, investor01, big.NewInt(10000), createOrderInput) // Cancel order @@ -239,7 +239,7 @@ func (s *OrderSuite) TestCancelOrder() { cancelOrderOutput := s.Tester.Advance(investor01, cancelOrderInput) s.Len(cancelOrderOutput.Notices, 1) - expectedCancelOrderOutput := fmt.Sprintf(`order canceled - {"id":1,"issuance_id":1,"token":"%s","investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"10000","interest_rate":"9","state":"canceled","created_at":%d,"updated_at":%d}`, + expectedCancelOrderOutput := fmt.Sprintf(`order canceled - {"id":1,"issuance_id":1,"token":"%s","investor":{"id":4,"role":"investor","address":"%s","social_accounts":[],"created_at":%d,"updated_at":0},"amount":"10000","interest_rate":"900","state":"canceled","created_at":%d,"updated_at":%d}`, token, investor01, baseTime, baseTime, baseTime) s.Equal(expectedCancelOrderOutput, string(cancelOrderOutput.Notices[0].Payload)) }