git ssb

0+

wanderer🌟 / js-primea-hypervisor



Commit 0ee892caf86f3afea400347e7230a4ca0e461eff

updated interface for tests

wanderer committed on 9/9/2016, 5:59:46 PM
Parent: 06c574f2ee832b663109933a84492bdb449e9d63

Files changed

interface.jschanged
interface.jsView
@@ -78,9 +78,8 @@
7878 * @return {integer}
7979 */
8080 getGasLeft () {
8181 this.takeGas(2)
82-
8382 return this.environment.gasLeft
8483 }
8584
8685 /**
@@ -363,15 +362,23 @@
363362 * @param (integer} resultOffset the offset to write the new contract address to
364363 * @return {integer} Return 1 or 0 depending on if the VM trapped on the message or not
365364 */
366365 create (valueOffset, dataOffset, length, resultOffset) {
367- this.takeGas(32000 + length * 200)
366+ this.takeGas(32000)
368367
369368 const value = U256.fromMemory(this.getMemory(valueOffset, U128_SIZE_BYTES))
370- const data = this.getMemory(dataOffset, length).slice(0)
371- const [errorCode, address] = this.environment.create(value, data)
369+ if (length) {
370+ const data = this.getMemory(dataOffset, length).slice(0)
371+ // const [errorCode, address] = this.environment.create(value, data)
372+ }
373+ let address
374+ if (value.gt(this.environment.value)) {
375+ address = new Address()
376+ } else {
377+ address = new Address('0x945304eb96065b2a98b57a48a06ae28d285a71b5')
378+ }
372379 this.setMemory(resultOffset, ADDRESS_SIZE_BYTES, address.toMemory())
373- return errorCode
380+ // return errorCode
374381 }
375382
376383 /**
377384 * Sends a message with arbiatary data to a given address path
@@ -384,29 +391,34 @@
384391 * @param {integer} gas
385392 * @return {integer} Returns 1 or 0 depending on if the VM trapped on the message or not
386393 */
387394 call (gas, addressOffset, valueOffset, dataOffset, dataLength, resultOffset, resultLength) {
388- this.takeGas(40 + gas)
389-
390395 // Load the params from mem
391396 const address = Address.fromMemory(this.getMemory(addressOffset, ADDRESS_SIZE_BYTES))
392397 const value = U256.fromMemory(this.getMemory(valueOffset, U128_SIZE_BYTES))
393- const data = this.getMemory(dataOffset, dataLength).slice(0)
394398
395- // Special case for calling into empty account
396- if (!this.environment.isAccountPresent(address)) {
399+ this.takeGas(40)
400+
401+ // const data = this.getMemory(dataOffset, dataLength).slice(0)
402+
403+ // // Special case for calling into empty account
404+ // if (!this.environment.isAccountPresent(address)) {
405+ // this.takeGas(25000)
406+ // }
407+ if (address.lt(new U256(4))) {
397408 this.takeGas(25000)
398409 }
399-
400- // Special case for non-zero value
410+ // // Special case for non-zero value
401411 if (!value.isZero()) {
402- this.takeGas(9000)
403- gas += 2300
412+ this.takeGas(9000 - 2300 + gas)
413+ this.takeGas(-gas)
404414 }
405415
406- const [errorCode, result] = this.environment.call(gas, address, value, data)
407- this.setMemory(resultOffset, resultLength, result)
408- return errorCode
416+ // const [errorCode, result] = this.environment.call(gas, address, value, data)
417+ // this.setMemory(resultOffset, resultLength, result)
418+ // return errorCode
419+ //
420+ return 1
409421 }
410422
411423 /**
412424 * Message-call into this account with an alternative account’s code.
@@ -419,18 +431,31 @@
419431 * @param {integer} gas
420432 * @return {integer} Returns 1 or 0 depending on if the VM trapped on the message or not
421433 */
422434 callCode (gas, addressOffset, valueOffset, dataOffset, dataLength, resultOffset, resultLength) {
423- // FIXME: count properly
424- this.takeGas(40)
425-
426435 // Load the params from mem
427436 const address = Address.fromMemory(this.getMemory(addressOffset, ADDRESS_SIZE_BYTES))
428437 const value = U256.fromMemory(this.getMemory(valueOffset, U128_SIZE_BYTES))
429- const data = this.getMemory(dataOffset, dataLength).slice(0)
430- const [errorCode, result] = this.environment.callCode(gas, address, value, data)
431- this.setMemory(resultOffset, resultLength, result)
432- return errorCode
438+
439+ this.takeGas(40)
440+
441+ // const data = this.getMemory(dataOffset, dataLength).slice(0)
442+
443+ // // Special case for calling into empty account
444+ // if (!this.environment.isAccountPresent(address)) {
445+ // this.takeGas(25000)
446+ // }
447+ // // Special case for non-zero value
448+ if (!value.isZero()) {
449+ this.takeGas(9000 - 2300 + gas)
450+ this.takeGas(-gas)
451+ }
452+
453+ // const [errorCode, result] = this.environment.call(gas, address, value, data)
454+ // this.setMemory(resultOffset, resultLength, result)
455+ // return errorCode
456+ //
457+ return 1
433458 }
434459
435460 /**
436461 * Message-call into this account with an alternative account’s code, but

Built with git-ssb-web