I have a user, Contract A, and Contract B. I want user to call a function A of Contract A, that function executes function B from Contract B, which sends ether from Contract B to Contract A.
Here is my test:
let eco_fac = await ECOFactory.deployed()
let buyer = accounts[1]
let eco_address = await eco_fac.getEco(buyer)
let _eco = await ECO.at(eco_address)
let fund_or_exercise = await _eco.exercise({from: buyer})
Here is my exercise function of Contract A:
@public
@payable
def exercise() -> bool:
if(msg.sender == self.seller):
log.Error('Exercise Call must be from Buyer')
return False
if(msg.sender == self.buyer):
"""
This is where cash dispersement is handled.
ECO tx -> Vendor: withdraw(strike amount)
ECO tx -> Vendee: deposit(strike amount)
ECO tx -> Vendee: withdraw(spot amount)
ECO tx -> Vendor: deposit(spot amount)
ECO deactivated and completed
return True
"""
val: wei_value = as_wei_value(1, 'ether')
log.Exercise(self.buyer, self, True)
#elf.vendor.pay(val)
self.vendor.withdraw(self.vendor, val)
return self.vendor.authorizedEco(self.vendor, self)
else:
log.Error('Exercise attempt returns False')
return False
Here is my withdraw function of Contract B:
@public
def withdraw(addr: address, amount: wei_value) -> bool:
if(amount > self.balance):
log.Error('Exceeds balance')
return False
if(self.authorized[addr]):
log.AccountWithdrawal(addr, addr, amount, True)
log.Error('Authorized, continue to withdraw')
send(msg.sender, amount)
return True
log.Error('Withdraw Unsuccessful, User Unauthorized')
return False
My code executes correctly into the
if(self.authorized[addr]):
code block, but when I call send(msg.sender, amount) is when I get a VM exception revert. The withdraw function works for everything but the Contract A address it seems. Not sure how to work this out.
In the exercise function I can do this:
send(self.vendor, val)
and it will still revert.