diff --git a/src/node/README.md b/src/node/README.md
index 9c15075e..db24a6c5 100644
--- a/src/node/README.md
+++ b/src/node/README.md
@@ -112,11 +112,11 @@ Example
```
{
- "timestamp": int64
"previous_hash": [32]byte
- "transactions": []Transaction
"added_registered_addresses": []string
"removed_registered_addresses": []string
+ "timestamp": int64
+ "transactions": []Transaction
}
```
@@ -124,11 +124,11 @@ Example
```
-The block timestamp
The hash of the previous block in the chain
-The block transactions
The added addresses registered in the PoH registry compared to the previous block
The removed addresses registered in the PoH registry compared to the previous block
+The block timestamp
+The block transactions
```
@@ -136,11 +136,11 @@ The removed addresses registered in the PoH registry compared to the previous bl
```
{
- "timestamp": 1667768884780639700
"previous_hash": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32]
- "transactions": []
"added_registered_addresses": ["0xf14DB86A3292ABaB1D4B912dbF55e8abc112593a"]
"removed_registered_addresses": ["0xb1477DcBBea001a339a92b031d14a011e36D008F"]
+ "timestamp": 1667768884780639700
+ "transactions": []
}
```
@@ -211,9 +211,9 @@ Example
```
{
- "address": string
- "is_registered": bool
- "value": uint64
+ "address": string
+ "is_yielding": bool
+ "value": uint64
}
```
@@ -232,7 +232,7 @@ The value at the transaction timestamp
```
{
"address": "0xf14DB86A3292ABaB1D4B912dbF55e8abc112593a"
- "has_income": true
+ "is_yielding": true
"value": 0
}
```
@@ -348,7 +348,7 @@ Example
{
"address": string
"block_height": int
- "has_income": bool
+ "is_yielding": bool
"output_index": uint16
"transaction_id": string
"value": uint64
@@ -375,7 +375,7 @@ The value at the transaction timestamp
{
"address": "0xf14DB86A3292ABaB1D4B912dbF55e8abc112593a"
"block_height": 0
- "has_income": true
+ "is_yielding": true
"output_index": 0
"transaction_id": "8ae72a72c0c99dc9d41c2b7d8ea67b5a2de25ff4463b1a53816ba179947ce77d"
"value": 0
diff --git a/src/node/protocol/validation/transactions_pool.go b/src/node/protocol/validation/transactions_pool.go
index db559406..6c99a328 100644
--- a/src/node/protocol/validation/transactions_pool.go
+++ b/src/node/protocol/validation/transactions_pool.go
@@ -83,11 +83,11 @@ func (pool *TransactionsPool) Validate(timestamp int64) {
nextBlockTimestamp := lastBlockTimestamp + pool.settings.ValidationTimestamp()
var reward uint64
var newAddresses []string
- var hasIncome bool
+ var isYielding bool
if lastBlockTimestamp == 0 {
reward = pool.settings.GenesisAmountInParticles()
newAddresses = []string{pool.validatorAddress}
- hasIncome = true
+ isYielding = true
} else if lastBlockTimestamp == timestamp {
pool.logger.Error("unable to create block, a block with the same timestamp is already in the blockchain")
return
@@ -152,12 +152,12 @@ func (pool *TransactionsPool) Validate(timestamp int64) {
}
for _, transaction := range transactions {
for _, output := range transaction.Outputs() {
- if output.IsRegistered() {
+ if output.IsYielding() {
newAddresses = append(newAddresses, output.Address())
}
}
}
- rewardTransaction, err := verification.NewRewardTransaction(pool.validatorAddress, hasIncome, timestamp, reward)
+ rewardTransaction, err := verification.NewRewardTransaction(pool.validatorAddress, isYielding, timestamp, reward)
if err != nil {
pool.logger.Error(fmt.Errorf("unable to create block, failed to create reward transaction: %w", err).Error())
return
diff --git a/src/node/protocol/verification/block.go b/src/node/protocol/verification/block.go
index cd4fe18c..33cbd91b 100644
--- a/src/node/protocol/verification/block.go
+++ b/src/node/protocol/verification/block.go
@@ -7,37 +7,23 @@ import (
)
type blockDto struct {
- Timestamp int64 `json:"timestamp"`
PreviousHash [32]byte `json:"previous_hash"`
- Transactions []*Transaction `json:"transactions"`
AddedRegisteredAddresses []string `json:"added_registered_addresses"`
RemovedRegisteredAddresses []string `json:"removed_registered_addresses"`
+ Timestamp int64 `json:"timestamp"`
+ Transactions []*Transaction `json:"transactions"`
}
type Block struct {
- timestamp int64
previousHash [32]byte
- transactions []*Transaction
addedRegisteredAddresses []string
removedRegisteredAddresses []string
+ timestamp int64
+ transactions []*Transaction
}
-func NewBlock(timestamp int64, previousHash [32]byte, transactions []*Transaction, addedRegisteredAddresses []string, removedRegisteredAddresses []string) *Block {
- return &Block{timestamp, previousHash, transactions, addedRegisteredAddresses, removedRegisteredAddresses}
-}
-
-func (block *Block) AddedRegisteredAddresses() []string {
- return block.addedRegisteredAddresses
-}
-
-func (block *Block) Hash() (hash [32]byte, err error) {
- marshaledBlock, err := block.MarshalJSON()
- if err != nil {
- err = fmt.Errorf("failed to marshal block: %w", err)
- return
- }
- hash = sha256.Sum256(marshaledBlock)
- return
+func NewBlock(previousHash [32]byte, addedRegisteredAddresses []string, removedRegisteredAddresses []string, timestamp int64, transactions []*Transaction) *Block {
+ return &Block{previousHash, addedRegisteredAddresses, removedRegisteredAddresses, timestamp, transactions}
}
func (block *Block) UnmarshalJSON(data []byte) error {
@@ -46,28 +32,53 @@ func (block *Block) UnmarshalJSON(data []byte) error {
if err != nil {
return err
}
- block.timestamp = dto.Timestamp
block.previousHash = dto.PreviousHash
- block.transactions = dto.Transactions
block.addedRegisteredAddresses = dto.AddedRegisteredAddresses
block.removedRegisteredAddresses = dto.RemovedRegisteredAddresses
+ block.timestamp = dto.Timestamp
+ block.transactions = dto.Transactions
return nil
}
func (block *Block) MarshalJSON() ([]byte, error) {
return json.Marshal(blockDto{
- Timestamp: block.timestamp,
PreviousHash: block.previousHash,
- Transactions: block.transactions,
AddedRegisteredAddresses: block.addedRegisteredAddresses,
RemovedRegisteredAddresses: block.removedRegisteredAddresses,
+ Timestamp: block.timestamp,
+ Transactions: block.transactions,
})
}
+func (block *Block) Hash() (hash [32]byte, err error) {
+ marshaledBlock, err := block.MarshalJSON()
+ if err != nil {
+ err = fmt.Errorf("failed to marshal block: %w", err)
+ return
+ }
+ hash = sha256.Sum256(marshaledBlock)
+ return
+}
+
+func (block *Block) ValidatorAddress() string {
+ var validatorAddress string
+ for i := len(block.transactions) - 1; i >= 0; i-- {
+ if block.transactions[i].HasReward() {
+ validatorAddress = block.transactions[i].RewardRecipientAddress()
+ break
+ }
+ }
+ return validatorAddress
+}
+
func (block *Block) PreviousHash() [32]byte {
return block.previousHash
}
+func (block *Block) AddedRegisteredAddresses() []string {
+ return block.addedRegisteredAddresses
+}
+
func (block *Block) RemovedRegisteredAddresses() []string {
return block.removedRegisteredAddresses
}
@@ -79,14 +90,3 @@ func (block *Block) Timestamp() int64 {
func (block *Block) Transactions() []*Transaction {
return block.transactions
}
-
-func (block *Block) ValidatorAddress() string {
- var validatorAddress string
- for i := len(block.transactions) - 1; i >= 0; i-- {
- if block.transactions[i].HasReward() {
- validatorAddress = block.transactions[i].RewardRecipientAddress()
- break
- }
- }
- return validatorAddress
-}
diff --git a/src/node/protocol/verification/blockchain.go b/src/node/protocol/verification/blockchain.go
index 9fd2862b..237615b4 100644
--- a/src/node/protocol/verification/blockchain.go
+++ b/src/node/protocol/verification/blockchain.go
@@ -85,7 +85,7 @@ func (blockchain *Blockchain) AddBlock(timestamp int64, transactionsBytes []byte
return fmt.Errorf("failed to unmarshal transactions: %w", err)
}
}
- block := NewBlock(timestamp, previousHash, transactions, addedRegisteredAddresses, removedRegisteredAddresses)
+ block := NewBlock(previousHash, addedRegisteredAddresses, removedRegisteredAddresses, timestamp, transactions)
return blockchain.addBlock(block)
}
@@ -608,7 +608,7 @@ func (blockchain *Blockchain) verifyBlock(neighborBlock *Block, previousBlockTim
return fmt.Errorf("a neighbor block transaction timestamp is too old: transaction timestamp: %d, id: %s", transaction.Timestamp(), transaction.Id())
}
for _, output := range transaction.Outputs() {
- if output.IsRegistered() {
+ if output.IsYielding() {
if err := blockchain.isRegistered(output.Address(), addedRegisteredAddresses, removedRegisteredAddresses); err != nil {
return err
}
@@ -691,13 +691,13 @@ func removeUtxo(utxos []*Utxo, transactionId string, outputIndex uint16) []*Utxo
func verifyIncomes(utxosByAddress map[string][]*Utxo) error {
for address, utxos := range utxosByAddress {
- var hasIncome bool
+ var isYielding bool
for _, utxo := range utxos {
- if utxo.IsRegistered() {
- if hasIncome {
+ if utxo.IsYielding() {
+ if isYielding {
return fmt.Errorf("income requested for several UTXOs for address: %s", address)
}
- hasIncome = true
+ isYielding = true
}
}
}
diff --git a/src/node/protocol/verification/output.go b/src/node/protocol/verification/output.go
index 2ebce316..51890840 100644
--- a/src/node/protocol/verification/output.go
+++ b/src/node/protocol/verification/output.go
@@ -5,26 +5,26 @@ import (
)
type outputDto struct {
- Address string `json:"address"`
- IsRegistered bool `json:"is_registered"`
- Value uint64 `json:"value"`
+ Address string `json:"address"`
+ IsYielding bool `json:"is_yielding"`
+ Value uint64 `json:"value"`
}
type Output struct {
- address string
- isRegistered bool
- value uint64
+ address string
+ isYielding bool
+ value uint64
}
-func NewOutput(address string, isRegistered bool, value uint64) *Output {
- return &Output{address, isRegistered, value}
+func NewOutput(address string, isYielding bool, value uint64) *Output {
+ return &Output{address, isYielding, value}
}
func (output *Output) MarshalJSON() ([]byte, error) {
return json.Marshal(outputDto{
- Address: output.address,
- IsRegistered: output.isRegistered,
- Value: output.value,
+ Address: output.address,
+ IsYielding: output.isYielding,
+ Value: output.value,
})
}
@@ -35,7 +35,7 @@ func (output *Output) UnmarshalJSON(data []byte) error {
return err
}
output.address = dto.Address
- output.isRegistered = dto.IsRegistered
+ output.isYielding = dto.IsYielding
output.value = dto.Value
return nil
}
@@ -44,8 +44,8 @@ func (output *Output) Address() string {
return output.address
}
-func (output *Output) IsRegistered() bool {
- return output.isRegistered
+func (output *Output) IsYielding() bool {
+ return output.isYielding
}
func (output *Output) InitialValue() uint64 {
diff --git a/src/node/protocol/verification/transaction.go b/src/node/protocol/verification/transaction.go
index 5fd62393..9341817c 100644
--- a/src/node/protocol/verification/transaction.go
+++ b/src/node/protocol/verification/transaction.go
@@ -25,8 +25,8 @@ type Transaction struct {
rewardValue uint64
}
-func NewRewardTransaction(address string, hasIncome bool, timestamp int64, value uint64) (*Transaction, error) {
- outputs := []*Output{NewOutput(address, hasIncome, value)}
+func NewRewardTransaction(address string, isYielding bool, timestamp int64, value uint64) (*Transaction, error) {
+ outputs := []*Output{NewOutput(address, isYielding, value)}
var inputs []*Input
id, err := generateId(inputs, outputs, timestamp)
if err != nil {
diff --git a/src/node/protocol/verification/utxo.go b/src/node/protocol/verification/utxo.go
index bc93c596..65a300b9 100644
--- a/src/node/protocol/verification/utxo.go
+++ b/src/node/protocol/verification/utxo.go
@@ -8,7 +8,7 @@ import (
type utxoDto struct {
Address string `json:"address"`
Timestamp int64 `json:"timestamp"`
- HasIncome bool `json:"has_income"`
+ IsYielding bool `json:"is_yielding"`
OutputIndex uint16 `json:"output_index"`
TransactionId string `json:"transaction_id"`
Value uint64 `json:"value"`
@@ -28,7 +28,7 @@ func (utxo *Utxo) MarshalJSON() ([]byte, error) {
return json.Marshal(utxoDto{
Address: utxo.Address(),
Timestamp: utxo.timestamp,
- HasIncome: utxo.IsRegistered(),
+ IsYielding: utxo.IsYielding(),
OutputIndex: utxo.outputIndex,
TransactionId: utxo.transactionId,
Value: utxo.InitialValue(),
@@ -42,7 +42,7 @@ func (utxo *Utxo) UnmarshalJSON(data []byte) error {
return err
}
utxo.InputInfo = NewInputInfo(dto.OutputIndex, dto.TransactionId)
- utxo.Output = NewOutput(dto.Address, dto.HasIncome, dto.Value)
+ utxo.Output = NewOutput(dto.Address, dto.IsYielding, dto.Value)
utxo.timestamp = dto.Timestamp
return nil
}
@@ -52,7 +52,7 @@ func (utxo *Utxo) Value(currentTimestamp int64, halfLifeInNanoseconds float64, i
return utxo.InitialValue()
}
x := float64(currentTimestamp - utxo.timestamp)
- if utxo.IsRegistered() {
+ if utxo.IsYielding() {
return utxo.g(halfLifeInNanoseconds, incomeBase, incomeLimit, x)
} else {
return utxo.f(halfLifeInNanoseconds, x)
diff --git a/src/ui/README.md b/src/ui/README.md
index ffe72492..50caf443 100644
--- a/src/ui/README.md
+++ b/src/ui/README.md
@@ -238,9 +238,9 @@ Example
```
{
- "address": string
- "is_registered": bool
- "value": uint64
+ "address": string
+ "is_yielding": bool
+ "value": uint64
}
```
@@ -259,7 +259,7 @@ The value at the transaction timestamp
```
{
"address": "0xf14DB86A3292ABaB1D4B912dbF55e8abc112593a"
- "has_income": true
+ "is_yielding": true
"value": 0
}
```
diff --git a/src/ui/main.go b/src/ui/main.go
index 1411ccdd..c34031fd 100644
--- a/src/ui/main.go
+++ b/src/ui/main.go
@@ -14,7 +14,7 @@ import (
"github.com/my-cloud/ruthenium/src/ui/server/index"
"github.com/my-cloud/ruthenium/src/ui/server/transaction"
"github.com/my-cloud/ruthenium/src/ui/server/transaction/info"
- "github.com/my-cloud/ruthenium/src/ui/server/transaction/status"
+ "github.com/my-cloud/ruthenium/src/ui/server/transaction/output/progress"
"github.com/my-cloud/ruthenium/src/ui/server/transactions"
"github.com/my-cloud/ruthenium/src/ui/server/wallet/address"
"github.com/my-cloud/ruthenium/src/ui/server/wallet/amount"
@@ -49,7 +49,7 @@ func main() {
http.Handle("/transaction", transaction.NewHandler(host, logger))
http.Handle("/transactions", transactions.NewHandler(host, logger))
http.Handle("/transaction/info", info.NewHandler(host, settings, watch, logger))
- http.Handle("/transaction/status", status.NewHandler(host, settings, watch, logger))
+ http.Handle("/transaction/output/progress", progress.NewHandler(host, settings, watch, logger))
http.Handle("/wallet/address", address.NewHandler(logger))
http.Handle("/wallet/amount", amount.NewHandler(host, settings, watch, logger))
logger.Info("user interface server is running...")
diff --git a/src/ui/server/transaction/status/handler.go b/src/ui/server/transaction/output/progress/handler.go
similarity index 75%
rename from src/ui/server/transaction/status/handler.go
rename to src/ui/server/transaction/output/progress/handler.go
index 35f9c688..68651fed 100644
--- a/src/ui/server/transaction/status/handler.go
+++ b/src/ui/server/transaction/output/progress/handler.go
@@ -1,14 +1,14 @@
-package status
+package progress
import (
"encoding/json"
- "errors"
"fmt"
"github.com/my-cloud/ruthenium/src/log"
"github.com/my-cloud/ruthenium/src/node/clock"
"github.com/my-cloud/ruthenium/src/node/network"
"github.com/my-cloud/ruthenium/src/node/protocol/verification"
"github.com/my-cloud/ruthenium/src/ui/server"
+ "github.com/my-cloud/ruthenium/src/ui/server/transaction/output"
"net/http"
)
@@ -28,22 +28,15 @@ func (handler *Handler) ServeHTTP(writer http.ResponseWriter, req *http.Request)
case http.MethodPut:
jsonWriter := server.NewIoWriter(writer, handler.logger)
decoder := json.NewDecoder(req.Body)
- var transaction *verification.Transaction
- err := decoder.Decode(&transaction)
+ var searchedUtxo *verification.Utxo
+ err := decoder.Decode(&searchedUtxo)
if err != nil {
- handler.logger.Error(fmt.Errorf("failed to decode transaction: %w", err).Error())
+ handler.logger.Error(fmt.Errorf("failed to decode utxo: %w", err).Error())
writer.WriteHeader(http.StatusBadRequest)
- jsonWriter.Write("invalid transaction")
- return
- } else if len(transaction.Outputs()) == 0 {
- handler.logger.Error(errors.New("transaction has no output").Error())
- writer.WriteHeader(http.StatusBadRequest)
- jsonWriter.Write("invalid transaction")
+ jsonWriter.Write("invalid utxo")
return
}
- lastOutputIndex := len(transaction.Outputs()) - 1
- lastOutput := transaction.Outputs()[lastOutputIndex]
- utxosBytes, err := handler.host.GetUtxos(lastOutput.Address())
+ utxosBytes, err := handler.host.GetUtxos(searchedUtxo.Address())
if err != nil {
handler.logger.Error(fmt.Errorf("failed to get UTXOs: %w", err).Error())
writer.WriteHeader(http.StatusInternalServerError)
@@ -60,14 +53,14 @@ func (handler *Handler) ServeHTTP(writer http.ResponseWriter, req *http.Request)
now := handler.watch.Now().UnixNano()
currentBlockHeight := (now - genesisTimestamp) / handler.settings.ValidationTimestamp()
currentBlockTimestamp := genesisTimestamp + currentBlockHeight*handler.settings.ValidationTimestamp()
- progress := &Progress{
+ progressInfo := &output.ProgressInfo{
CurrentBlockTimestamp: currentBlockTimestamp,
ValidationTimestamp: handler.settings.ValidationTimestamp(),
}
for _, utxo := range utxos {
- if utxo.TransactionId() == transaction.Id() && utxo.OutputIndex() == uint16(lastOutputIndex) {
- progress.TransactionStatus = "confirmed"
- handler.sendResponse(writer, progress)
+ if utxo.TransactionId() == searchedUtxo.TransactionId() && utxo.OutputIndex() == searchedUtxo.OutputIndex() {
+ progressInfo.TransactionStatus = "confirmed"
+ handler.sendResponse(writer, progressInfo)
return
}
}
@@ -95,9 +88,9 @@ func (handler *Handler) ServeHTTP(writer http.ResponseWriter, req *http.Request)
return
}
for _, validatedTransaction := range blocks[0].Transactions() {
- if validatedTransaction.Id() == transaction.Id() {
- progress.TransactionStatus = "validated"
- handler.sendResponse(writer, progress)
+ if validatedTransaction.Id() == searchedUtxo.TransactionId() {
+ progressInfo.TransactionStatus = "validated"
+ handler.sendResponse(writer, progressInfo)
return
}
}
@@ -115,21 +108,21 @@ func (handler *Handler) ServeHTTP(writer http.ResponseWriter, req *http.Request)
return
}
for _, pendingTransaction := range transactions {
- if pendingTransaction.Id() == transaction.Id() {
- progress.TransactionStatus = "sent"
- handler.sendResponse(writer, progress)
+ if pendingTransaction.Id() == searchedUtxo.TransactionId() {
+ progressInfo.TransactionStatus = "sent"
+ handler.sendResponse(writer, progressInfo)
return
}
}
- progress.TransactionStatus = "rejected"
- handler.sendResponse(writer, progress)
+ progressInfo.TransactionStatus = "rejected"
+ handler.sendResponse(writer, progressInfo)
default:
handler.logger.Error("invalid HTTP method")
writer.WriteHeader(http.StatusBadRequest)
}
}
-func (handler *Handler) sendResponse(writer http.ResponseWriter, progress *Progress) {
+func (handler *Handler) sendResponse(writer http.ResponseWriter, progress *output.ProgressInfo) {
marshaledResponse, err := json.Marshal(progress)
if err != nil {
handler.logger.Error(fmt.Errorf("failed to marshal progress: %w", err).Error())
diff --git a/src/ui/server/transaction/status/progress.go b/src/ui/server/transaction/output/progress_info.go
similarity index 81%
rename from src/ui/server/transaction/status/progress.go
rename to src/ui/server/transaction/output/progress_info.go
index c61d676e..8dde849a 100644
--- a/src/ui/server/transaction/status/progress.go
+++ b/src/ui/server/transaction/output/progress_info.go
@@ -1,6 +1,6 @@
-package status
+package output
-type Progress struct {
+type ProgressInfo struct {
CurrentBlockTimestamp int64 `json:"current_block_timestamp"`
TransactionStatus string `json:"transaction_status"`
ValidationTimestamp int64 `json:"validation_timestamp"`
diff --git a/templates/index.html b/templates/index.html
index 7ea515ca..50f61ce2 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -110,7 +110,7 @@
Transactions Pool
});
$(function () {
- let pendingTransaction;
+ let lastRestUtxo;
$("#send_tokens_button").click(function () {
if (!keyPair) {
@@ -154,12 +154,12 @@ Transactions Pool
const recipientAddress = $("#recipient_address").val();
const spend = {
"address": recipientAddress,
- "is_registered": false,
+ "is_yielding": false,
"value": value,
}
const rest = {
"address": senderAddress,
- "is_registered": isIncomeUpdateRequested,
+ "is_yielding": isIncomeUpdateRequested,
"value": response.rest,
}
const transaction = {
@@ -177,7 +177,14 @@ Transactions Pool
success: function (response) {
if (response === "success") {
alert("Send success");
- pendingTransaction = transaction
+ lastRestUtxo = {
+ "address": rest.address,
+ "timestamp": transaction.timestamp,
+ "is_yielding": rest.is_yielding,
+ "output_index": 1,
+ "transaction_id": transaction.id,
+ "value": rest.value,
+ }
} else {
alert("Send failed: " + response)
}
@@ -249,15 +256,15 @@ Transactions Pool
function refresh_progress() {
const progressBar = document.querySelector('.progress-circle');
- if (pendingTransaction === undefined) {
+ if (lastRestUtxo === undefined) {
progressBar.style.background = `conic-gradient(white 100%, white 0)`;
progressBar.textContent = "";
} else {
$.ajax({
- url: "/transaction/status",
+ url: "/transaction/output/progress",
type: "PUT",
contentType: "application/json",
- data: JSON.stringify(pendingTransaction),
+ data: JSON.stringify(lastRestUtxo),
success: function (response) {
const now = new Date().getTime() * 1000000
let angle = (now - response.current_block_timestamp) / response.validation_timestamp * 100
diff --git a/test/node/protocol/protocoltest/block.go b/test/node/protocol/protocoltest/block.go
index 7516877d..6244dbdf 100644
--- a/test/node/protocol/protocoltest/block.go
+++ b/test/node/protocol/protocoltest/block.go
@@ -7,11 +7,11 @@ import (
func NewGenesisBlock(validatorWalletAddress string, genesisValue uint64) *verification.Block {
genesisTransaction, _ := verification.NewRewardTransaction(validatorWalletAddress, true, 0, genesisValue)
transactions := []*verification.Transaction{genesisTransaction}
- return verification.NewBlock(0, [32]byte{}, transactions, nil, nil)
+ return verification.NewBlock([32]byte{}, nil, nil, 0, transactions)
}
func NewRewardedBlock(previousHash [32]byte, timestamp int64) *verification.Block {
rewardTransaction, _ := verification.NewRewardTransaction("recipient", false, 0, 0)
transactions := []*verification.Transaction{rewardTransaction}
- return verification.NewBlock(timestamp, previousHash, transactions, nil, nil)
+ return verification.NewBlock(previousHash, nil, nil, timestamp, transactions)
}
diff --git a/test/node/protocol/protocoltest/transaction.go b/test/node/protocol/protocoltest/transaction.go
index ba18f0d4..87661a18 100644
--- a/test/node/protocol/protocoltest/transaction.go
+++ b/test/node/protocol/protocoltest/transaction.go
@@ -8,7 +8,7 @@ import (
"github.com/my-cloud/ruthenium/src/node/protocol/verification"
)
-func NewSignedTransactionRequest(inputsValue uint64, fee uint64, outputIndex uint16, recipientAddress string, privateKey *encryption.PrivateKey, publicKey *encryption.PublicKey, timestamp int64, transactionId string, value uint64, isRegistered bool) []byte {
+func NewSignedTransactionRequest(inputsValue uint64, fee uint64, outputIndex uint16, recipientAddress string, privateKey *encryption.PrivateKey, publicKey *encryption.PublicKey, timestamp int64, transactionId string, value uint64, isYielding bool) []byte {
marshalledInput, _ := json.Marshal(struct {
OutputIndex uint16 `json:"output_index"`
TransactionId string `json:"transaction_id"`
@@ -21,7 +21,7 @@ func NewSignedTransactionRequest(inputsValue uint64, fee uint64, outputIndex uin
input, _ := verification.NewInput(outputIndex, transactionId, publicKey.String(), signatureString)
sent := verification.NewOutput(recipientAddress, false, value)
restValue := inputsValue - value - fee
- rest := verification.NewOutput(recipientAddress, isRegistered, restValue)
+ rest := verification.NewOutput(recipientAddress, isYielding, restValue)
inputs := []*verification.Input{input}
outputs := []*verification.Output{sent, rest}
id := generateId(inputs, outputs, timestamp)
diff --git a/test/node/protocol/verification/blockchain_test.go b/test/node/protocol/verification/blockchain_test.go
index 20f4c2bb..6e15e2fd 100644
--- a/test/node/protocol/verification/blockchain_test.go
+++ b/test/node/protocol/verification/blockchain_test.go
@@ -440,7 +440,7 @@ func Test_Update_NeighborNewBlockTransactionFeeIsNegative_IsNotReplaced(t *testi
invalidTransaction,
rewardTransaction,
}
- block3 := verification.NewBlock(now, hash2, transactions, []string{address}, nil)
+ block3 := verification.NewBlock(hash2, []string{address}, nil, now, transactions)
neighborMock.GetBlocksFunc = func(uint64) ([]byte, error) {
blocks := []*verification.Block{block1, block2, block3}
blocksBytes, _ := json.Marshal(blocks)
@@ -501,7 +501,7 @@ func Test_Update_NeighborNewBlockTransactionFeeIsTooLow_IsNotReplaced(t *testing
invalidTransaction,
rewardTransaction,
}
- block3 := verification.NewBlock(now, hash2, transactions, []string{address}, nil)
+ block3 := verification.NewBlock(hash2, []string{address}, nil, now, transactions)
neighborMock.GetBlocksFunc = func(uint64) ([]byte, error) {
blocks := []*verification.Block{block1, block2, block3}
blocksBytes, _ := json.Marshal(blocks)
@@ -563,7 +563,7 @@ func Test_Update_NeighborNewBlockTransactionTimestampIsTooFarInTheFuture_IsNotRe
invalidTransaction,
rewardTransaction,
}
- block3 := verification.NewBlock(now, hash2, transactions, []string{address}, nil)
+ block3 := verification.NewBlock(hash2, []string{address}, nil, now, transactions)
neighborMock.GetBlocksFunc = func(uint64) ([]byte, error) {
blocks := []*verification.Block{block1, block2, block3}
blocksBytes, _ := json.Marshal(blocks)
@@ -625,7 +625,7 @@ func Test_Update_NeighborNewBlockTransactionTimestampIsTooOld_IsNotReplaced(t *t
invalidTransaction,
rewardTransaction,
}
- block3 := verification.NewBlock(now, hash2, transactions, []string{address}, nil)
+ block3 := verification.NewBlock(hash2, []string{address}, nil, now, transactions)
neighborMock.GetBlocksFunc = func(uint64) ([]byte, error) {
blocks := []*verification.Block{block1, block2, block3}
blocksBytes, _ := json.Marshal(blocks)
@@ -688,7 +688,7 @@ func Test_Update_NeighborNewBlockTransactionInputSignatureIsInvalid_IsNotReplace
invalidTransaction,
rewardTransaction,
}
- block3 := verification.NewBlock(now, hash2, transactions, []string{address}, nil)
+ block3 := verification.NewBlock(hash2, []string{address}, nil, now, transactions)
neighborMock.GetBlocksFunc = func(uint64) ([]byte, error) {
blocks := []*verification.Block{block1, block2, block3}
blocksBytes, _ := json.Marshal(blocks)
@@ -750,7 +750,7 @@ func Test_Update_NeighborNewBlockTransactionInputPublicKeyIsInvalid_IsNotReplace
invalidTransaction,
rewardTransaction,
}
- block3 := verification.NewBlock(now, hash2, transactions, []string{address}, nil)
+ block3 := verification.NewBlock(hash2, []string{address}, nil, now, transactions)
neighborMock.GetBlocksFunc = func(uint64) ([]byte, error) {
blocks := []*verification.Block{block1, block2, block3}
blocksBytes, _ := json.Marshal(blocks)
@@ -800,7 +800,7 @@ func Test_Update_NeighborAddressIsNotRegistered_IsNotReplaced(t *testing.T) {
hash2, _ := block2.Hash()
rewardTransaction, _ := verification.NewRewardTransaction(notRegisteredAddress, false, now, 0)
transactions := []*verification.Transaction{rewardTransaction}
- block3 := verification.NewBlock(now, hash2, transactions, []string{notRegisteredAddress}, nil)
+ block3 := verification.NewBlock(hash2, []string{notRegisteredAddress}, nil, now, transactions)
neighborMock.GetBlocksFunc = func(uint64) ([]byte, error) {
blocks := []*verification.Block{block1, block2, block3}
blocksBytes, _ := json.Marshal(blocks)
@@ -863,7 +863,7 @@ func Test_Update_NeighborBlockRegisteredOutputAddressHasNotBeenAdded_IsNotReplac
invalidTransaction,
rewardTransaction,
}
- block3 := verification.NewBlock(now, hash2, transactions, []string{address}, nil)
+ block3 := verification.NewBlock(hash2, []string{address}, nil, now, transactions)
neighborMock.GetBlocksFunc = func(uint64) ([]byte, error) {
blocks := []*verification.Block{block1, block2, block3}
blocksBytes, _ := json.Marshal(blocks)
@@ -926,7 +926,7 @@ func Test_Update_NeighborBlockRegisteredOutputAddressHasBeenRemoved_IsNotReplace
invalidTransaction,
rewardTransaction,
}
- block3 := verification.NewBlock(now, hash2, transactions, []string{address}, []string{removedAddress})
+ block3 := verification.NewBlock(hash2, []string{address}, []string{removedAddress}, now, transactions)
neighborMock.GetBlocksFunc = func(uint64) ([]byte, error) {
blocks := []*verification.Block{block1, block2, block3}
blocksBytes, _ := json.Marshal(blocks)
diff --git a/test/node/protocol/verification/utxo_test.go b/test/node/protocol/verification/utxo_test.go
index f937bd69..aea20ba3 100644
--- a/test/node/protocol/verification/utxo_test.go
+++ b/test/node/protocol/verification/utxo_test.go
@@ -19,7 +19,7 @@ const (
)
// ////////////////////////////////// WITH INCOME ////////////////////////////////////
-func Test_Value_ValueIsMaxUint64AndHasIncome_ReturnsValueWithIncome(t *testing.T) {
+func Test_Value_ValueIsMaxUint64AndIsYielding_ReturnsValueWithIncome(t *testing.T) {
// Arrange
var value uint64 = math.MaxUint64 // 18446744073709551615
output := verification.NewOutput("", true, value)
@@ -33,7 +33,7 @@ func Test_Value_ValueIsMaxUint64AndHasIncome_ReturnsValueWithIncome(t *testing.T
test.Assert(t, actualValueAfterHalfLife == expectedValueAfterHalfLife, fmt.Sprintf("Wrong value. Expected: %d - Actual: %d", expectedValueAfterHalfLife, actualValueAfterHalfLife))
}
-func Test_Value_ValueIsTwiceTheLimitAndHasIncome_ReturnsValueWithIncome(t *testing.T) {
+func Test_Value_ValueIsTwiceTheLimitAndIsYielding_ReturnsValueWithIncome(t *testing.T) {
// Arrange
value := 2 * limit
output := verification.NewOutput("", true, value)
@@ -47,7 +47,7 @@ func Test_Value_ValueIsTwiceTheLimitAndHasIncome_ReturnsValueWithIncome(t *testi
test.Assert(t, actualValueAfterHalfLife == expectedValueAfterHalfLife, fmt.Sprintf("Wrong value. Expected: %d - Actual: %d", expectedValueAfterHalfLife, actualValueAfterHalfLife))
}
-func Test_Value_ValueIsLimitAndHasIncome_ReturnsValueWithIncome(t *testing.T) {
+func Test_Value_ValueIsLimitAndIsYielding_ReturnsValueWithIncome(t *testing.T) {
// Arrange
value := limit
output := verification.NewOutput("", true, value)
@@ -64,7 +64,7 @@ func Test_Value_ValueIsLimitAndHasIncome_ReturnsValueWithIncome(t *testing.T) {
test.Assert(t, actualValueAfterHalfLife == expectedValueAfterHalfLife, fmt.Sprintf("Wrong value. Expected: %d - Actual: %d", expectedValueAfterHalfLife, actualValueAfterHalfLife))
}
-func Test_Value_ValueIs1AndHasIncome_ReturnsValueWithIncome(t *testing.T) {
+func Test_Value_ValueIs1AndIsYielding_ReturnsValueWithIncome(t *testing.T) {
// Arrange
var value uint64 = 1
output := verification.NewOutput("", true, value)
@@ -80,7 +80,7 @@ func Test_Value_ValueIs1AndHasIncome_ReturnsValueWithIncome(t *testing.T) {
test.Assert(t, actualValueAfter1Minute >= value, fmt.Sprintf("Wrong value. Expected a value >= %d - Actual: %d", value, actualValueAfter1Minute))
}
-func Test_Value_ValueIs0AndHasIncome_ReturnsValueWithIncome(t *testing.T) {
+func Test_Value_ValueIs0AndIsYielding_ReturnsValueWithIncome(t *testing.T) {
// Arrange
var value uint64 = 0
output := verification.NewOutput("", true, value)
@@ -94,7 +94,7 @@ func Test_Value_ValueIs0AndHasIncome_ReturnsValueWithIncome(t *testing.T) {
test.Assert(t, actualValueAfterHalfLife == expectedValueAfterHalfLife, fmt.Sprintf("Wrong value. Expected: %d - Actual: %d", expectedValueAfterHalfLife, actualValueAfterHalfLife))
}
-func Test_Value_SamePortionOfHalfLifeElapsedWithIncome_ReturnsSameValue(t *testing.T) {
+func Test_Value_SamePortionOfHalfLifeElapsedAndIsYielding_ReturnsSameValue(t *testing.T) {
// Arrange
var value uint64 = 0
output := verification.NewOutput("", true, value)
@@ -109,7 +109,7 @@ func Test_Value_SamePortionOfHalfLifeElapsedWithIncome_ReturnsSameValue(t *testi
test.Assert(t, value1 == value2, "Values are not equals whereas it should be")
}
-func Test_Value_SameElapsedTimeWithIncome_ReturnsSameValue(t *testing.T) {
+func Test_Value_SameElapsedTimeAndIsYielding_ReturnsSameValue(t *testing.T) {
// Arrange
var value uint64 = 0
var outputTimestamp1 int64 = 0
@@ -130,7 +130,7 @@ func Test_Value_SameElapsedTimeWithIncome_ReturnsSameValue(t *testing.T) {
}
// ////////////////////////////////// WITHOUT INCOME ////////////////////////////////////
-func Test_Value_ValueIsMaxUint64AndHasNoIncome_ReturnsValueWithoutIncome(t *testing.T) {
+func Test_Value_ValueIsMaxUint64AndIsNotYielding_ReturnsValueWithoutIncome(t *testing.T) {
// Arrange
var value uint64 = math.MaxUint64 // 18446744073709551615
output := verification.NewOutput("", false, value)
@@ -144,7 +144,7 @@ func Test_Value_ValueIsMaxUint64AndHasNoIncome_ReturnsValueWithoutIncome(t *test
test.Assert(t, actualValueAfterHalfLife == expectedValueAfterHalfLife, fmt.Sprintf("Wrong value. Expected: %d - Actual: %d", expectedValueAfterHalfLife, actualValueAfterHalfLife))
}
-func Test_Value_ValueIsTwiceTheLimitAndHasNoIncome_ReturnsValueWithoutIncome(t *testing.T) {
+func Test_Value_ValueIsTwiceTheLimitAndIsNotYielding_ReturnsValueWithoutIncome(t *testing.T) {
// Arrange
value := 2 * limit
output := verification.NewOutput("", false, value)
@@ -158,7 +158,7 @@ func Test_Value_ValueIsTwiceTheLimitAndHasNoIncome_ReturnsValueWithoutIncome(t *
test.Assert(t, actualValueAfterHalfLife == expectedValueAfterHalfLife, fmt.Sprintf("Wrong value. Expected: %d - Actual: %d", expectedValueAfterHalfLife, actualValueAfterHalfLife))
}
-func Test_Value_ValueIsLimitAndHasNoIncome_ReturnsValueWithoutIncome(t *testing.T) {
+func Test_Value_ValueIsLimitAndIsNotYielding_ReturnsValueWithoutIncome(t *testing.T) {
// Arrange
value := limit
output := verification.NewOutput("", false, value)
@@ -172,7 +172,7 @@ func Test_Value_ValueIsLimitAndHasNoIncome_ReturnsValueWithoutIncome(t *testing.
test.Assert(t, actualValueAfterHalfLife == expectedValueAfterHalfLife, fmt.Sprintf("Wrong value. Expected: %d - Actual: %d", expectedValueAfterHalfLife, actualValueAfterHalfLife))
}
-func Test_Value_ValueIs1AndHasNoIncome_ReturnsValueWithoutIncome(t *testing.T) {
+func Test_Value_ValueIs1AndIsNotYielding_ReturnsValueWithoutIncome(t *testing.T) {
// Arrange
var value uint64 = 1
output := verification.NewOutput("", false, value)
@@ -189,7 +189,7 @@ func Test_Value_ValueIs1AndHasNoIncome_ReturnsValueWithoutIncome(t *testing.T) {
test.Assert(t, actualValueAfter1Minute == expectedValueAfter1Minute, fmt.Sprintf("Wrong value. Expected: %d - Actual: %d", expectedValueAfter1Minute, actualValueAfter1Minute))
}
-func Test_Value_ValueIs0AndHasNoIncome_ReturnsValueWithoutIncome(t *testing.T) {
+func Test_Value_ValueIs0AndIsNotYielding_ReturnsValueWithoutIncome(t *testing.T) {
// Arrange
var value uint64 = 0
output := verification.NewOutput("", false, value)
diff --git a/test/ui/server/transaction/handler_test.go b/test/ui/server/transaction/handler_test.go
index 2beb70cf..1fd75610 100644
--- a/test/ui/server/transaction/handler_test.go
+++ b/test/ui/server/transaction/handler_test.go
@@ -6,11 +6,11 @@ import (
"errors"
"fmt"
"github.com/my-cloud/ruthenium/src/node/protocol/verification"
+ "github.com/my-cloud/ruthenium/src/ui/server/transaction"
"net/http"
"net/http/httptest"
"testing"
- "github.com/my-cloud/ruthenium/src/ui/server/transaction"
"github.com/my-cloud/ruthenium/test"
"github.com/my-cloud/ruthenium/test/log/logtest"
"github.com/my-cloud/ruthenium/test/node/network/networktest"
diff --git a/test/ui/server/transaction/status/handler_test.go b/test/ui/server/transaction/output/progress/handler_test.go
similarity index 82%
rename from test/ui/server/transaction/status/handler_test.go
rename to test/ui/server/transaction/output/progress/handler_test.go
index 0a212fd3..66264902 100644
--- a/test/ui/server/transaction/status/handler_test.go
+++ b/test/ui/server/transaction/output/progress/handler_test.go
@@ -1,4 +1,4 @@
-package info
+package progress
import (
"bytes"
@@ -6,7 +6,8 @@ import (
"errors"
"fmt"
"github.com/my-cloud/ruthenium/src/node/protocol/verification"
- "github.com/my-cloud/ruthenium/src/ui/server/transaction/status"
+ "github.com/my-cloud/ruthenium/src/ui/server/transaction/output"
+ "github.com/my-cloud/ruthenium/src/ui/server/transaction/output/progress"
"github.com/my-cloud/ruthenium/test"
"github.com/my-cloud/ruthenium/test/log/logtest"
"github.com/my-cloud/ruthenium/test/node/clock/clocktest"
@@ -26,7 +27,7 @@ func Test_ServeHTTP_InvalidHttpMethod_BadRequest(t *testing.T) {
neighborMock := new(networktest.NeighborMock)
watchMock := new(clocktest.WatchMock)
settings := new(servertest.SettingsMock)
- handler := status.NewHandler(neighborMock, settings, watchMock, logger)
+ handler := progress.NewHandler(neighborMock, settings, watchMock, logger)
recorder := httptest.NewRecorder()
invalidHttpMethods := []string{http.MethodGet, http.MethodHead, http.MethodPost, http.MethodPatch, http.MethodDelete, http.MethodConnect, http.MethodOptions, http.MethodTrace}
for _, method := range invalidHttpMethods {
@@ -43,7 +44,7 @@ func Test_ServeHTTP_InvalidHttpMethod_BadRequest(t *testing.T) {
}
}
-func Test_ServeHTTP_UndecipherableTransaction_BadRequest(t *testing.T) {
+func Test_ServeHTTP_UndecipherableUtxo_BadRequest(t *testing.T) {
// Arrange
neighborMock := new(networktest.NeighborMock)
settings := new(servertest.SettingsMock)
@@ -54,7 +55,7 @@ func Test_ServeHTTP_UndecipherableTransaction_BadRequest(t *testing.T) {
settings.ValidationTimestampFunc = func() int64 { return 1 }
watchMock := new(clocktest.WatchMock)
logger := logtest.NewLoggerMock()
- handler := status.NewHandler(neighborMock, settings, watchMock, logger)
+ handler := progress.NewHandler(neighborMock, settings, watchMock, logger)
data := ""
marshalledData, _ := json.Marshal(data)
body := bytes.NewReader(marshalledData)
@@ -65,7 +66,7 @@ func Test_ServeHTTP_UndecipherableTransaction_BadRequest(t *testing.T) {
handler.ServeHTTP(recorder, request)
// Assert
- isNeighborMethodCalled := len(neighborMock.AddTransactionCalls()) != 0
+ isNeighborMethodCalled := len(neighborMock.GetUtxosCalls()) != 0
test.Assert(t, !isNeighborMethodCalled, "Neighbor method is called whereas it should not.")
expectedStatusCode := 400
test.Assert(t, recorder.Code == expectedStatusCode, fmt.Sprintf("Wrong response status code. expected: %d actual: %d", expectedStatusCode, recorder.Code))
@@ -83,11 +84,11 @@ func Test_ServeHTTP_GetUtxosError_ReturnsInternalServerError(t *testing.T) {
settings.IncomeLimitInParticlesFunc = func() uint64 { return 0 }
settings.ParticlesPerTokenFunc = func() uint64 { return 1 }
settings.ValidationTimestampFunc = func() int64 { return 1 }
- handler := status.NewHandler(neighborMock, settings, watchMock, logger)
+ handler := progress.NewHandler(neighborMock, settings, watchMock, logger)
recorder := httptest.NewRecorder()
- transaction, _ := verification.NewRewardTransaction("", false, 0, 0)
- marshalledTransaction, _ := json.Marshal(transaction)
- body := bytes.NewReader(marshalledTransaction)
+ utxo := verification.NewUtxo(&verification.InputInfo{}, &verification.Output{}, 0)
+ marshalledUtxo, _ := json.Marshal(utxo)
+ body := bytes.NewReader(marshalledUtxo)
request := httptest.NewRequest(http.MethodPut, urlTarget, body)
// Act
@@ -115,11 +116,11 @@ func Test_ServeHTTP_GetFirstBlockTimestampError_ReturnsInternalServerError(t *te
settings.IncomeLimitInParticlesFunc = func() uint64 { return 0 }
settings.ParticlesPerTokenFunc = func() uint64 { return 1 }
settings.ValidationTimestampFunc = func() int64 { return 1 }
- handler := status.NewHandler(neighborMock, settings, watchMock, logger)
+ handler := progress.NewHandler(neighborMock, settings, watchMock, logger)
recorder := httptest.NewRecorder()
- transaction, _ := verification.NewRewardTransaction("", false, 0, 0)
- marshalledTransaction, _ := json.Marshal(transaction)
- body := bytes.NewReader(marshalledTransaction)
+ utxo := verification.NewUtxo(&verification.InputInfo{}, &verification.Output{}, 0)
+ marshalledUtxo, _ := json.Marshal(utxo)
+ body := bytes.NewReader(marshalledUtxo)
request := httptest.NewRequest(http.MethodPut, urlTarget, body)
// Act
@@ -148,11 +149,11 @@ func Test_ServeHTTP_GetBlocksError_ReturnsInternalServerError(t *testing.T) {
settings.IncomeLimitInParticlesFunc = func() uint64 { return 0 }
settings.ParticlesPerTokenFunc = func() uint64 { return 1 }
settings.ValidationTimestampFunc = func() int64 { return 1 }
- handler := status.NewHandler(neighborMock, settings, watchMock, logger)
+ handler := progress.NewHandler(neighborMock, settings, watchMock, logger)
recorder := httptest.NewRecorder()
- transaction, _ := verification.NewRewardTransaction("", false, 0, 0)
- marshalledTransaction, _ := json.Marshal(transaction)
- body := bytes.NewReader(marshalledTransaction)
+ utxo := verification.NewUtxo(&verification.InputInfo{}, &verification.Output{}, 0)
+ marshalledUtxo, _ := json.Marshal(utxo)
+ body := bytes.NewReader(marshalledUtxo)
request := httptest.NewRequest(http.MethodPut, urlTarget, body)
// Act
@@ -172,7 +173,7 @@ func Test_ServeHTTP_GetTransactionsError_ReturnsInternalServerError(t *testing.T
marshalledEmptyArray := []byte{91, 93}
neighborMock.GetUtxosFunc = func(string) ([]byte, error) { return marshalledEmptyArray, nil }
neighborMock.GetFirstBlockTimestampFunc = func() (int64, error) { return 0, nil }
- blocks := []*verification.Block{verification.NewBlock(0, [32]byte{}, nil, nil, nil)}
+ blocks := []*verification.Block{verification.NewBlock([32]byte{}, nil, nil, 0, nil)}
marshalledBlocks, _ := json.Marshal(blocks)
neighborMock.GetBlocksFunc = func(uint64) ([]byte, error) { return marshalledBlocks, nil }
neighborMock.GetTransactionsFunc = func() ([]byte, error) { return nil, errors.New("") }
@@ -184,11 +185,11 @@ func Test_ServeHTTP_GetTransactionsError_ReturnsInternalServerError(t *testing.T
settings.IncomeLimitInParticlesFunc = func() uint64 { return 0 }
settings.ParticlesPerTokenFunc = func() uint64 { return 1 }
settings.ValidationTimestampFunc = func() int64 { return 1 }
- handler := status.NewHandler(neighborMock, settings, watchMock, logger)
+ handler := progress.NewHandler(neighborMock, settings, watchMock, logger)
recorder := httptest.NewRecorder()
- transaction, _ := verification.NewRewardTransaction("", false, 0, 0)
- marshalledTransaction, _ := json.Marshal(transaction)
- body := bytes.NewReader(marshalledTransaction)
+ utxo := verification.NewUtxo(&verification.InputInfo{}, &verification.Output{}, 0)
+ marshalledUtxo, _ := json.Marshal(utxo)
+ body := bytes.NewReader(marshalledUtxo)
request := httptest.NewRequest(http.MethodPut, urlTarget, body)
// Act
@@ -208,7 +209,7 @@ func Test_ServeHTTP_TransactionNotFound_ReturnsRejected(t *testing.T) {
marshalledEmptyArray := []byte{91, 93}
neighborMock.GetUtxosFunc = func(string) ([]byte, error) { return marshalledEmptyArray, nil }
neighborMock.GetFirstBlockTimestampFunc = func() (int64, error) { return 0, nil }
- blocks := []*verification.Block{verification.NewBlock(0, [32]byte{}, nil, nil, nil)}
+ blocks := []*verification.Block{verification.NewBlock([32]byte{}, nil, nil, 0, nil)}
marshalledBlocks, _ := json.Marshal(blocks)
neighborMock.GetBlocksFunc = func(uint64) ([]byte, error) { return marshalledBlocks, nil }
neighborMock.GetTransactionsFunc = func() ([]byte, error) { return marshalledEmptyArray, nil }
@@ -220,11 +221,11 @@ func Test_ServeHTTP_TransactionNotFound_ReturnsRejected(t *testing.T) {
settings.IncomeLimitInParticlesFunc = func() uint64 { return 0 }
settings.ParticlesPerTokenFunc = func() uint64 { return 1 }
settings.ValidationTimestampFunc = func() int64 { return 1 }
- handler := status.NewHandler(neighborMock, settings, watchMock, logger)
+ handler := progress.NewHandler(neighborMock, settings, watchMock, logger)
recorder := httptest.NewRecorder()
- transaction, _ := verification.NewRewardTransaction("", false, 0, 0)
- marshalledTransaction, _ := json.Marshal(transaction)
- body := bytes.NewReader(marshalledTransaction)
+ utxo := verification.NewUtxo(&verification.InputInfo{}, &verification.Output{}, 0)
+ marshalledUtxo, _ := json.Marshal(utxo)
+ body := bytes.NewReader(marshalledUtxo)
request := httptest.NewRequest(http.MethodPut, urlTarget, body)
// Act
@@ -237,10 +238,10 @@ func Test_ServeHTTP_TransactionNotFound_ReturnsRejected(t *testing.T) {
test.Assert(t, recorder.Code == expectedStatusCode, fmt.Sprintf("Wrong response status code. expected: %d actual: %d", expectedStatusCode, recorder.Code))
expectedStatus := "rejected"
response := recorder.Body.Bytes()
- var progress *status.Progress
- err := json.Unmarshal(response, &progress)
+ var progressInfo *output.ProgressInfo
+ err := json.Unmarshal(response, &progressInfo)
fmt.Println(err)
- actualStatus := progress.TransactionStatus
+ actualStatus := progressInfo.TransactionStatus
test.Assert(t, actualStatus == expectedStatus, fmt.Sprintf("Wrong response. expected: %s actual: %s", expectedStatus, actualStatus))
}
@@ -252,8 +253,8 @@ func Test_ServeHTTP_UtxoFound_ReturnsConfirmed(t *testing.T) {
transactionId := transaction.Id()
inputInfo := verification.NewInputInfo(0, transactionId)
utxo := verification.NewUtxo(inputInfo, &verification.Output{}, 0)
- marshalledEmptyUtxos, _ := json.Marshal([]*verification.Utxo{utxo})
- neighborMock.GetUtxosFunc = func(string) ([]byte, error) { return marshalledEmptyUtxos, nil }
+ marshalledUtxos, _ := json.Marshal([]*verification.Utxo{utxo})
+ neighborMock.GetUtxosFunc = func(string) ([]byte, error) { return marshalledUtxos, nil }
neighborMock.GetFirstBlockTimestampFunc = func() (int64, error) { return 0, nil }
watchMock := new(clocktest.WatchMock)
watchMock.NowFunc = func() time.Time { return time.Unix(0, 0) }
@@ -263,10 +264,10 @@ func Test_ServeHTTP_UtxoFound_ReturnsConfirmed(t *testing.T) {
settings.IncomeLimitInParticlesFunc = func() uint64 { return 0 }
settings.ParticlesPerTokenFunc = func() uint64 { return 1 }
settings.ValidationTimestampFunc = func() int64 { return 1 }
- handler := status.NewHandler(neighborMock, settings, watchMock, logger)
+ handler := progress.NewHandler(neighborMock, settings, watchMock, logger)
recorder := httptest.NewRecorder()
- marshalledTransaction, _ := json.Marshal(transaction)
- body := bytes.NewReader(marshalledTransaction)
+ marshalledUtxo, _ := json.Marshal(utxo)
+ body := bytes.NewReader(marshalledUtxo)
request := httptest.NewRequest(http.MethodPut, urlTarget, body)
// Act
@@ -279,10 +280,10 @@ func Test_ServeHTTP_UtxoFound_ReturnsConfirmed(t *testing.T) {
test.Assert(t, recorder.Code == expectedStatusCode, fmt.Sprintf("Wrong response status code. expected: %d actual: %d", expectedStatusCode, recorder.Code))
expectedStatus := "confirmed"
response := recorder.Body.Bytes()
- var progress *status.Progress
- err := json.Unmarshal(response, &progress)
+ var progressInfo *output.ProgressInfo
+ err := json.Unmarshal(response, &progressInfo)
fmt.Println(err)
- actualStatus := progress.TransactionStatus
+ actualStatus := progressInfo.TransactionStatus
test.Assert(t, actualStatus == expectedStatus, fmt.Sprintf("Wrong response. expected: %s actual: %s", expectedStatus, actualStatus))
}
@@ -294,7 +295,7 @@ func Test_ServeHTTP_ValidatedTransactionFound_ReturnsValidated(t *testing.T) {
neighborMock.GetUtxosFunc = func(string) ([]byte, error) { return marshalledEmptyArray, nil }
neighborMock.GetFirstBlockTimestampFunc = func() (int64, error) { return 0, nil }
transaction, _ := verification.NewRewardTransaction("", false, 0, 0)
- blocks := []*verification.Block{verification.NewBlock(0, [32]byte{}, []*verification.Transaction{transaction}, nil, nil)}
+ blocks := []*verification.Block{verification.NewBlock([32]byte{}, nil, nil, 0, []*verification.Transaction{transaction})}
marshalledBlocks, _ := json.Marshal(blocks)
neighborMock.GetBlocksFunc = func(uint64) ([]byte, error) { return marshalledBlocks, nil }
watchMock := new(clocktest.WatchMock)
@@ -305,10 +306,12 @@ func Test_ServeHTTP_ValidatedTransactionFound_ReturnsValidated(t *testing.T) {
settings.IncomeLimitInParticlesFunc = func() uint64 { return 0 }
settings.ParticlesPerTokenFunc = func() uint64 { return 1 }
settings.ValidationTimestampFunc = func() int64 { return 1 }
- handler := status.NewHandler(neighborMock, settings, watchMock, logger)
+ handler := progress.NewHandler(neighborMock, settings, watchMock, logger)
recorder := httptest.NewRecorder()
- marshalledTransaction, _ := json.Marshal(transaction)
- body := bytes.NewReader(marshalledTransaction)
+ outputIndex := 0
+ utxo := verification.NewUtxo(verification.NewInputInfo(uint16(outputIndex), transaction.Id()), transaction.Outputs()[outputIndex], transaction.Timestamp())
+ marshalledUtxo, _ := json.Marshal(utxo)
+ body := bytes.NewReader(marshalledUtxo)
request := httptest.NewRequest(http.MethodPut, urlTarget, body)
// Act
@@ -321,10 +324,10 @@ func Test_ServeHTTP_ValidatedTransactionFound_ReturnsValidated(t *testing.T) {
test.Assert(t, recorder.Code == expectedStatusCode, fmt.Sprintf("Wrong response status code. expected: %d actual: %d", expectedStatusCode, recorder.Code))
expectedStatus := "validated"
response := recorder.Body.Bytes()
- var progress *status.Progress
- err := json.Unmarshal(response, &progress)
+ var progressInfo *output.ProgressInfo
+ err := json.Unmarshal(response, &progressInfo)
fmt.Println(err)
- actualStatus := progress.TransactionStatus
+ actualStatus := progressInfo.TransactionStatus
test.Assert(t, actualStatus == expectedStatus, fmt.Sprintf("Wrong response. expected: %s actual: %s", expectedStatus, actualStatus))
}
@@ -335,7 +338,7 @@ func Test_ServeHTTP_PendingTransactionFound_ReturnsSent(t *testing.T) {
marshalledEmptyArray := []byte{91, 93}
neighborMock.GetUtxosFunc = func(string) ([]byte, error) { return marshalledEmptyArray, nil }
neighborMock.GetFirstBlockTimestampFunc = func() (int64, error) { return 0, nil }
- blocks := []*verification.Block{verification.NewBlock(0, [32]byte{}, nil, nil, nil)}
+ blocks := []*verification.Block{verification.NewBlock([32]byte{}, nil, nil, 0, nil)}
marshalledBlocks, _ := json.Marshal(blocks)
neighborMock.GetBlocksFunc = func(uint64) ([]byte, error) { return marshalledBlocks, nil }
transaction, _ := verification.NewRewardTransaction("", false, 0, 0)
@@ -350,10 +353,12 @@ func Test_ServeHTTP_PendingTransactionFound_ReturnsSent(t *testing.T) {
settings.IncomeLimitInParticlesFunc = func() uint64 { return 0 }
settings.ParticlesPerTokenFunc = func() uint64 { return 1 }
settings.ValidationTimestampFunc = func() int64 { return 1 }
- handler := status.NewHandler(neighborMock, settings, watchMock, logger)
+ handler := progress.NewHandler(neighborMock, settings, watchMock, logger)
recorder := httptest.NewRecorder()
- marshalledTransaction, _ := json.Marshal(transaction)
- body := bytes.NewReader(marshalledTransaction)
+ outputIndex := 0
+ utxo := verification.NewUtxo(verification.NewInputInfo(uint16(outputIndex), transaction.Id()), transaction.Outputs()[outputIndex], transaction.Timestamp())
+ marshalledUtxo, _ := json.Marshal(utxo)
+ body := bytes.NewReader(marshalledUtxo)
request := httptest.NewRequest(http.MethodPut, urlTarget, body)
// Act
@@ -366,9 +371,9 @@ func Test_ServeHTTP_PendingTransactionFound_ReturnsSent(t *testing.T) {
test.Assert(t, recorder.Code == expectedStatusCode, fmt.Sprintf("Wrong response status code. expected: %d actual: %d", expectedStatusCode, recorder.Code))
expectedStatus := "sent"
response := recorder.Body.Bytes()
- var progress *status.Progress
- err := json.Unmarshal(response, &progress)
+ var progressInfo *output.ProgressInfo
+ err := json.Unmarshal(response, &progressInfo)
fmt.Println(err)
- actualStatus := progress.TransactionStatus
+ actualStatus := progressInfo.TransactionStatus
test.Assert(t, actualStatus == expectedStatus, fmt.Sprintf("Wrong response. expected: %s actual: %s", expectedStatus, actualStatus))
}