Skip to content
Snippets Groups Projects
  • Hans Moog's avatar
    7ba94158
    Feat/wallet (#533) · 7ba94158
    Hans Moog authored
    * Feat: started adding new logic to the wallet package
    
    * Feat: intermediary commit
    
    * Feat: added Outputs to wallet
    
    * Feat: started implementing SendFunds
    
    * Feat: added AddressManager + refactored code
    
    * Feat: tx gets constructed
    
    * Feat: txs get sent now
    
    * Feat: fixed bug after merge
    
    * Fix: fixed faucet
    
    * Fix: fix double spend tool
    
    * Fix: refactored broken tests
    
    * Fix: fixed additional tests
    
    * Fix: fixed some integration tests
    
    * Fix: fixed some issues
    
    * Fix: fixed further bugs in integration tests
    
    * Fix: fixed some bugs
    
    * :white_check_mark: Make WaitToKillTimeInSeconds a parameter
    
    * :wrench: Set default ParaWaitToKill to 60 seconds
    
    * :bug: Fix bug
    
    * Feat: added an output manager
    
    * Fix: fixed bug
    
    * Feat: added new features to the wallet
    
    * Feat: added missing comments
    
    * Feat: updated some stuff
    
    * Feat: started to implement a cli wallet
    
    * Feat: added new features to cli wallet
    
    * Feat: added more features to cli wallet
    
    * Feat: MOAR FEATURES
    
    * Feat: finished wallet
    
    * Fix: fixed bug due to refactor
    
    * Fix: fixed bugs
    
    * Refactor: removed comments from private methods
    
    * do not ignore client lib
    
    * move wallet inside of the client dir
    
    * do not ignore client in docker build
    
    * go fmt yourself
    
    * Feat: added config to wallet
    
    * Feat: exe creates default config upon first launch
    
    * Feat: updated gitignore
    
    * Feat: refactored some code
    
    * Feat: added ERROR to all "non-fatal" error messages
    
    * Feat: removed error prefix from call and moved to func
    
    * Feat: indented error message
    
    * Feat: make commands look like params in useage print
    
    * Feat: reordered commands and params
    
    * Feat: fixed bug with colored coins creation
    
    * Fix: fixed missing unit tests
    
    * Feat: added message to sendfunds
    
    * Feat: added message for faucet POW call
    
    * Feat: intermediary commit
    
    * Fix: Enable server-status to get server information
    
    * Fix: Fix dependency cycle
    
    * Fix: Fix unit test errors
    
    * Fix: Fix integration test
    
    * Fix: Fix consensus integration test
    
    * Fix: fix :dog:
    
    * Refactor: Reorganize the wallet files to make it cleaner
    
    * Fix: Fix :dog:
    
    * :package:
    
     Add script for building cli-wallet binaries
    
    Co-authored-by: default avatarHans Moog <hm@mkjc.net>
    Co-authored-by: default avatarcapossele <angelocapossele@gmail.com>
    Co-authored-by: default avatarWolfgang Welz <welzwo@gmail.com>
    Co-authored-by: default avatarjkrvivian <jkrvivian@gmail.com>
    Feat/wallet (#533)
    Hans Moog authored
    * Feat: started adding new logic to the wallet package
    
    * Feat: intermediary commit
    
    * Feat: added Outputs to wallet
    
    * Feat: started implementing SendFunds
    
    * Feat: added AddressManager + refactored code
    
    * Feat: tx gets constructed
    
    * Feat: txs get sent now
    
    * Feat: fixed bug after merge
    
    * Fix: fixed faucet
    
    * Fix: fix double spend tool
    
    * Fix: refactored broken tests
    
    * Fix: fixed additional tests
    
    * Fix: fixed some integration tests
    
    * Fix: fixed some issues
    
    * Fix: fixed further bugs in integration tests
    
    * Fix: fixed some bugs
    
    * :white_check_mark: Make WaitToKillTimeInSeconds a parameter
    
    * :wrench: Set default ParaWaitToKill to 60 seconds
    
    * :bug: Fix bug
    
    * Feat: added an output manager
    
    * Fix: fixed bug
    
    * Feat: added new features to the wallet
    
    * Feat: added missing comments
    
    * Feat: updated some stuff
    
    * Feat: started to implement a cli wallet
    
    * Feat: added new features to cli wallet
    
    * Feat: added more features to cli wallet
    
    * Feat: MOAR FEATURES
    
    * Feat: finished wallet
    
    * Fix: fixed bug due to refactor
    
    * Fix: fixed bugs
    
    * Refactor: removed comments from private methods
    
    * do not ignore client lib
    
    * move wallet inside of the client dir
    
    * do not ignore client in docker build
    
    * go fmt yourself
    
    * Feat: added config to wallet
    
    * Feat: exe creates default config upon first launch
    
    * Feat: updated gitignore
    
    * Feat: refactored some code
    
    * Feat: added ERROR to all "non-fatal" error messages
    
    * Feat: removed error prefix from call and moved to func
    
    * Feat: indented error message
    
    * Feat: make commands look like params in useage print
    
    * Feat: reordered commands and params
    
    * Feat: fixed bug with colored coins creation
    
    * Fix: fixed missing unit tests
    
    * Feat: added message to sendfunds
    
    * Feat: added message for faucet POW call
    
    * Feat: intermediary commit
    
    * Fix: Enable server-status to get server information
    
    * Fix: Fix dependency cycle
    
    * Fix: Fix unit test errors
    
    * Fix: Fix integration test
    
    * Fix: Fix consensus integration test
    
    * Fix: fix :dog:
    
    * Refactor: Reorganize the wallet files to make it cleaner
    
    * Fix: Fix :dog:
    
    * :package:
    
     Add script for building cli-wallet binaries
    
    Co-authored-by: default avatarHans Moog <hm@mkjc.net>
    Co-authored-by: default avatarcapossele <angelocapossele@gmail.com>
    Co-authored-by: default avatarWolfgang Welz <welzwo@gmail.com>
    Co-authored-by: default avatarjkrvivian <jkrvivian@gmail.com>
snapshot_test.go 2.63 KiB
package tangle

import (
	"bytes"
	"testing"

	"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/address"
	"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/balance"
	"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/branchmanager"
	"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/transaction"
	"github.com/iotaledger/hive.go/kvstore/mapdb"
	"github.com/stretchr/testify/assert"
)

func TestLoadSnapshot(t *testing.T) {
	tangle := New(mapdb.NewMapDB())

	snapshot := map[transaction.ID]map[address.Address][]*balance.Balance{
		transaction.GenesisID: {
			address.Random(): []*balance.Balance{
				balance.New(balance.ColorIOTA, 337),
			},

			address.Random(): []*balance.Balance{
				balance.New(balance.ColorIOTA, 1000),
				balance.New(balance.ColorIOTA, 1000),
			},
		},
	}
	tangle.LoadSnapshot(snapshot)

	// check whether outputs can be retrieved from tangle
	for addr, balances := range snapshot[transaction.GenesisID] {
		cachedOutput := tangle.TransactionOutput(transaction.NewOutputID(addr, transaction.GenesisID))
		cachedOutput.Consume(func(output *Output) {
			assert.Equal(t, addr, output.Address())
			assert.ElementsMatch(t, balances, output.Balances())
			assert.True(t, output.Solid())
			assert.Equal(t, branchmanager.MasterBranchID, output.BranchID())
		})
	}
}

func TestSnapshotMarshalUnmarshal(t *testing.T) {
	const genesisBalance = 1000000000
	seed := newSeed()
	genesisAddr := seed.Address(GENESIS)

	snapshot := Snapshot{
		transaction.GenesisID: {
			genesisAddr: {
				balance.New(balance.ColorIOTA, genesisBalance),
			},
		},
	}

	// includes txs count
	const int64ByteSize = 8
	expectedLength := int64ByteSize
	for _, addresses := range snapshot {
		// tx id
		expectedLength += transaction.IDLength
		// addr count
		expectedLength += int64ByteSize
		for _, balances := range addresses {
			// addr
			expectedLength += address.Length
			// balance count
			expectedLength += int64ByteSize
			// balances
			expectedLength += len(balances) * (int64ByteSize + balance.ColorLength)
		}
	}

	var buf bytes.Buffer
	written, err := snapshot.WriteTo(&buf)
	assert.NoError(t, err, "writing the snapshot to the buffer should succeed")
	assert.EqualValues(t, expectedLength, written, "written byte count should match the expected count")

	snapshotFromBytes := Snapshot{}
	read, err := snapshotFromBytes.ReadFrom(&buf)
	assert.NoError(t, err, "expected no error from reading valid snapshot bytes")
	assert.EqualValues(t, expectedLength, read, "read byte count should match the expected count")

	// check that the source and unmarshaled snapshot are equivalent
	assert.Equal(t, snapshot, snapshotFromBytes)
}