Created
October 18, 2017 19:09
-
-
Save krgn/f668fa8a2ae69cf8012b30cadd4fa9e7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let accountShouldCreateUser = | |
ftestCaseAsync "account should create user" $ async { | |
let source = ContractSource.read "../../../build" "FileSyncContract" | |
let password = "password" | |
/// personal stuff | |
let name = "karsten" | |
let! personalAddress = Web3().Personal.NewAccount.SendRequestAsync(password) | |
let personalAccount = ManagedAccount(personalAddress, password) | |
let personalWeb3 = Web3 personalAccount | |
let! receipt = Eth.prefundAddress personalAddress /// eth.coinbase giving me some money | |
let! balance = Web3().Eth.GetBalance.SendRequestAsync(personalAddress) | |
printfn "address: %A has: %A" personalAddress balance.Value | |
/// admin stuff | |
let adminAddress = "0x12890d2cce102216644c59dae5baed380d84830c" | |
let adminAccount = ManagedAccount(adminAddress, password) | |
let adminWeb3 = Web3 adminAccount | |
let! receipt = | |
adminWeb3.Eth.DeployContract.SendRequestAndWaitForReceiptAsync( | |
source.Abi, | |
source.Bin, | |
adminAddress, | |
HexBigInteger(BigInteger((1000000))), | |
null) | |
printfn "contract: %A" receipt.ContractAddress | |
let contract = personalWeb3.Eth.GetContract(source.Abi, receipt.ContractAddress) | |
let userEvent = contract.GetEvent("User") | |
let createFunc = contract.GetFunction("createUser") | |
let! receipt = | |
createFunc.SendTransactionAndWaitForReceiptAsync( | |
personalAddress, | |
HexBigInteger(Numerics.BigInteger(4700000)), | |
null, | |
null, | |
name) | |
printfn "created user in: %A" receipt.TransactionHash | |
let userEvents = | |
userEvent.DecodeAllEventsForEvent<FileSync.UserEvent> receipt.Logs | |
for ev in userEvents do | |
printfn "user name: %A address: %A" ev.Event.Name ev.Event.Address | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment