// generateSpendableKey creates the keys and unlock conditions a given index of a // seed. func generateSpendableKey(seed modules.Seed, index uint64) spendableKey { // Generate the keys and unlock conditions. entropy := crypto.HashAll(seed, index) sk, pk := crypto.GenerateKeyPairDeterministic(entropy) return spendableKey{ UnlockConditions: generateUnlockConditions(pk), SecretKeys: []crypto.SecretKey{sk}, } }
// 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") } }