當前位置: 首頁>>代碼示例>>Golang>>正文


Golang HostDBEntry.StoragePrice方法代碼示例

本文整理匯總了Golang中github.com/NebulousLabs/Sia/modules.HostDBEntry.StoragePrice方法的典型用法代碼示例。如果您正苦於以下問題:Golang HostDBEntry.StoragePrice方法的具體用法?Golang HostDBEntry.StoragePrice怎麽用?Golang HostDBEntry.StoragePrice使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/NebulousLabs/Sia/modules.HostDBEntry的用法示例。


在下文中一共展示了HostDBEntry.StoragePrice方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestEditor

// TestEditor tests the failure conditions of the Editor method. The method is
// more fully tested in the host integration test.
func TestEditor(t *testing.T) {
	// use a mock hostdb to supply hosts
	hdb := &editorHostDB{
		hosts: make(map[modules.NetAddress]modules.HostDBEntry),
	}
	c := &Contractor{
		hdb: hdb,
	}

	// empty contract
	_, err := c.Editor(modules.RenterContract{})
	if err == nil {
		t.Error("expected error, got nil")
	}

	// expired contract
	c.blockHeight = 3
	_, err = c.Editor(modules.RenterContract{})
	if err == nil {
		t.Error("expected error, got nil")
	}
	c.blockHeight = 0

	// expensive host
	_, hostPublicKey := crypto.GenerateKeyPairDeterministic([32]byte{})
	dbe := modules.HostDBEntry{
		PublicKey: types.SiaPublicKey{
			Algorithm: types.SignatureEd25519,
			Key:       hostPublicKey[:],
		},
	}
	dbe.AcceptingContracts = true
	dbe.StoragePrice = types.NewCurrency64(^uint64(0))
	hdb.hosts["foo"] = dbe
	_, err = c.Editor(modules.RenterContract{NetAddress: "foo"})
	if err == nil {
		t.Error("expected error, got nil")
	}

	// invalid contract
	dbe.StoragePrice = types.NewCurrency64(500)
	hdb.hosts["bar"] = dbe
	_, err = c.Editor(modules.RenterContract{NetAddress: "bar"})
	if err == nil {
		t.Error("expected error, got nil")
	}

	// spent contract
	contract := modules.RenterContract{
		NetAddress: "bar",
		LastRevision: types.FileContractRevision{
			NewValidProofOutputs: []types.SiacoinOutput{
				{Value: types.NewCurrency64(0)},
				{Value: types.NewCurrency64(^uint64(0))},
			},
		},
	}
	_, err = c.Editor(contract)
	if err == nil {
		t.Error("expected error, got nil")
	}
}
開發者ID:robvanmieghem,項目名稱:Sia,代碼行數:64,代碼來源:upload_test.go


注:本文中的github.com/NebulousLabs/Sia/modules.HostDBEntry.StoragePrice方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。