[contracts] Use command line parameters for ContractInteractions

This commit is contained in:
Mark Spanbroek 2022-04-14 10:34:42 +02:00 committed by markspanbroek
parent 0738606303
commit 142ddd0fd3
3 changed files with 20 additions and 4 deletions

View File

@ -29,7 +29,16 @@ proc new*(_: type ContractInteractions,
proving: Proving.new(proofs)
)
proc new*(_: type ContractInteractions): ContractInteractions =
let provider = JsonRpcProvider.new("ws://localhost:8545")
let signer = provider.getSigner()
proc new*(_: type ContractInteractions,
providerUrl: string,
account = Address.default): ContractInteractions =
let provider = JsonRpcProvider.new(providerUrl)
var signer: Signer
if account == Address.default:
signer = provider.getSigner()
else:
signer = provider.getSigner(account)
ContractInteractions.new(signer, deployment())
proc new*(_: type ContractInteractions): ContractInteractions =
ContractInteractions.new("ws://localhost:8545")

View File

@ -122,7 +122,7 @@ proc new*(T: type DaggerServer, config: DaggerConf): T =
engine = BlockExcEngine.new(localStore, wallet, network, discovery)
store = NetworkStore.new(engine, localStore)
erasure = Erasure.new(store, leoEncoderProvider, leoDecoderProvider)
contracts = ContractInteractions.new()
contracts = ContractInteractions.new(config.ethProvider, config.ethAccount)
daggerNode = DaggerNodeRef.new(switch, store, engine, erasure, discovery, contracts)
restServer = RestServerRef.new(
daggerNode.initRestApi(),

View File

@ -1,5 +1,6 @@
import ./ethertest
import dagger/contracts
import ./examples
ethersuite "Storage Contract Interactions":
@ -13,6 +14,12 @@ ethersuite "Storage Contract Interactions":
let deployment = deployment()
check ContractInteractions.new(signer, deployment) != nil
test "can be instantiated with a provider url and account":
let url = "http://localhost:8545"
let account = Address.example
check ContractInteractions.new(url) != nil
check ContractInteractions.new(url, account) != nil
test "provides purchasing":
check contracts.purchasing != nil